1
0
forked from 0ad/0ad

Fix for pthread_create - assumed new thread started before _beginthread returns. Fixed by heap-allocating the parameter to thread_start

This was SVN commit r1004.
This commit is contained in:
Simon Brenner 2004-08-16 14:30:18 +00:00
parent 8e823492b5
commit 5575409959

View File

@ -341,9 +341,10 @@ struct ThreadParam
static unsigned __stdcall thread_start(void* arg)
{
const ThreadParam* param = (const ThreadParam*)arg;
ThreadParam* param = (ThreadParam*)arg;
param->func(param->user_arg);
delete param;
return 0;
}
@ -353,8 +354,13 @@ int pthread_create(pthread_t* thread, const void* attr, void*(*func)(void*), voi
UNUSED(attr);
// can't use asm - _beginthreadex might be a func ptr (with DLL CRT)
const ThreadParam param = { func, user_arg };
*thread = (pthread_t)_beginthreadex(0, 0, thread_start, (void*)&param, 0, 0);
// Heap Allocate - we can't make sure that the other thread's thread_start
// function is run before we exit this stack frame
ThreadParam *param = new ThreadParam;
param->func=func;
param->user_arg=user_arg;
*thread = (pthread_t)_beginthreadex(0, 0, thread_start, (void*)param, 0, 0);
return 0;
}