From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:44 +0000 (-0700) Subject: lib/thread: Change VThread_CreateThread prototype X-Git-Tag: stable-10.2.0~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecdc55d43ab00c0a0454af1bc15a8b215f086c55;p=thirdparty%2Fopen-vm-tools.git lib/thread: Change VThread_CreateThread prototype 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). --- diff --git a/open-vm-tools/lib/poll/poll.c b/open-vm-tools/lib/poll/poll.c index f1c0184bf..5b8d41691 100644 --- a/open-vm-tools/lib/poll/poll.c +++ b/open-vm-tools/lib/poll/poll.c @@ -2031,10 +2031,8 @@ PollUnitTest_StateMachine(void *clientData) // IN: Unused 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; @@ -2081,10 +2079,8 @@ PollUnitTest_StateMachine(void *clientData) // IN: Unused 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;