Skip to content
Snippets Groups Projects
Commit 1dbbd0fc authored by deuce's avatar deuce
Browse files

Use pthread_attr_destroy() to avoid stepping on a different threads stack

size.
parent beac09d6
No related branches found
No related tags found
No related merge requests found
...@@ -59,23 +59,19 @@ ulong _beginthread(void( *start_address )( void * ) ...@@ -59,23 +59,19 @@ ulong _beginthread(void( *start_address )( void * )
,unsigned stack_size, void *arglist) ,unsigned stack_size, void *arglist)
{ {
pthread_t thread; pthread_t thread;
static pthread_attr_t attr; pthread_attr_t attr;
static size_t default_stack; size_t default_stack;
static int attr_initialized=0;
pthread_attr_init(&attr); /* initialize attribute structure */
if(!attr_initialized) { /* set thread attributes to PTHREAD_CREATE_DETACHED which will ensure
pthread_attr_init(&attr); /* initialize attribute structure */ that thread resources are freed on exit() */
/* set thread attributes to PTHREAD_CREATE_DETACHED which will ensure pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
that thread resources are freed on exit() */
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_attr_getstacksize(&attr, &default_stack);
attr_initialized=1;
}
/* Default stack size in BSD is too small for JS stuff */ /* Default stack size in BSD is too small for JS stuff */
/* Force to at least 256k */ /* Force to at least 256k */
#define XPDEV_MIN_THREAD_STACK_SIZE (256*1024) #define XPDEV_MIN_THREAD_STACK_SIZE (256*1024)
if(stack_size==0 && default_stack < XPDEV_MIN_THREAD_STACK_SIZE) if(stack_size==0 && pthread_attr_getstacksize(&attr, &default_stack)==0
&& default_stack < XPDEV_MIN_THREAD_STACK_SIZE)
stack_size=XPDEV_MIN_THREAD_STACK_SIZE; stack_size=XPDEV_MIN_THREAD_STACK_SIZE;
if(stack_size!=0) if(stack_size!=0)
...@@ -92,8 +88,10 @@ ulong _beginthread(void( *start_address )( void * ) ...@@ -92,8 +88,10 @@ ulong _beginthread(void( *start_address )( void * )
/* POSIX defines this arg as "void *(*start_address)" */ /* POSIX defines this arg as "void *(*start_address)" */
,(void * (*)(void *)) start_address ,(void * (*)(void *)) start_address
,arglist)==0) ,arglist)==0)
pthread_attr_destroy(&attr);
return((int) thread /* thread handle */); return((int) thread /* thread handle */);
pthread_attr_destroy(&attr);
return(-1); /* error */ return(-1); /* error */
} }
#else #else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment