diff --git a/src/xpdev/threadwrap.c b/src/xpdev/threadwrap.c index e356b690dc646b074d4f0591d5617053d69a9ee7..13b43e980c5c6cb52840438644a5815a12b9c5cc 100644 --- a/src/xpdev/threadwrap.c +++ b/src/xpdev/threadwrap.c @@ -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