[Vm-dev] win32 SetEvent, ResetEvent and MsgWaitForMultipleObjects

Holger Freyther holger at freyther.de
Wed Aug 30 17:37:47 UTC 2017

Hi Eliot, Bert,

as part of reading the "goToSleep" primitive I had a look at Windows and the last time I dealt with win32 API was quite some time ago so maybe I am wrong but doesn't the time slice below look like a race condition? If not what am I missing?

VM Thread			Socket Read Thread


				 -> SetEvent(vmWakeUpEvent)


Couldn't we have lost the vmWakeUpEvent for the socket and then wait the full timeout? The history in Opensmalltalk-vm doesn't go far but couldn't we create the vmWakeUpEvent with the autoreset flag?

thank you


Code snippets:

sqInt ioRelinquishProcessorForMicroseconds(sqInt microSeconds)
        /* wake us up if something happens */
        if (WAIT_TIMEOUT ==
                MsgWaitForMultipleObjects(1, &vmWakeUpEvent, FALSE,
                            microSeconds / 1000, QS_ALLINPUT))

int synchronizedSignalSemaphoreWithIndex(int semaIndex)
  int result;

  /* Do our job - this is now synchronized in signalSemaphoreWithIndex */
  result = signalSemaphoreWithIndex(semaIndex);
  /* wake up interpret() if sleeping */

static DWORD WINAPI readWatcherThread(privateSocketStruct *pss)
  struct timeval tv= { 1000, 0 }; /* Timeout value == 1000 sec */
  fd_set fds;
  int n, doWait;

  while(1) {
        switch(pss->readWatcherOp) {
        case WatchData:
          /* Data may be available */
          pss->sockState |= SOCK_DATA_READABLE;

More information about the Vm-dev mailing list