]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/thread: Change VThread_CreateThread prototype
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:44 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:44 +0000 (11:23 -0700)
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).

open-vm-tools/lib/poll/poll.c

index f1c0184bfc08deceb3409cec9157005cf121d657..5b8d416914c2573548ba4f6f462072d2e83d98aa 100644 (file)
@@ -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;