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