Change the VThread_CreateThread prototype from this:
VThreadID VThread_CreateThread(void (*fn)(void *), void *data,
VThread tid, const char *name);
to this:
Bool VThread_CreateThread(void (*fn)(void *), void *data,
const char *name, VThread *tid);
The new prototype returns essentially the same information, with
one important advancement: we can contractually guarantee the 'tid'
field is populated BEFORE the child thread starts. This neatly
avoids all sorts of interesting race conditions where the child
starts running before the CreateThread function passes back its
return value. This style of design is preferred by operating
systems (see Posix pthread_create, Win32 CreateThread).
raceTestIter = 0;
dummyCount = 0;
exitThread = FALSE;
- cbRaceThread = VThread_CreateThread(PollAddRemoveCBThread,
- NULL,
- VTHREAD_INVALID_ID,
- "PollAddRemoveCBThread");
+ VThread_CreateThread(PollAddRemoveCBThread, NULL,
+ "PollAddRemoveCBThread", &cbRaceThread);
if (cbRaceThread == VTHREAD_INVALID_ID) {
Warning("%s: failure -- error creating thread\n", __FUNCTION__);
state += 3;
deviceEv1Count = 0;
eventTestIter = 0;
exitThread = FALSE;
- cbRaceThread = VThread_CreateThread(PollLockContentionThread,
- NULL,
- VTHREAD_INVALID_ID,
- "PollLockContention");
+ VThread_CreateThread(PollLockContentionThread, NULL,
+ "PollLockContention", &cbRaceThread);
if (cbRaceThread == VTHREAD_INVALID_ID) {
Warning("%s: failure -- error creating thread\n", __FUNCTION__);
state += 3;