windows/SysSemaphore.hpp File Reference
#include "rexx.h"
#include "SysDebug.hpp"
#include "Utilities.hpp"
#include <stdlib.h>
#include <stdio.h>
Include dependency graph for windows/SysSemaphore.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SysSemaphore
 
class  SysMutex
 

Functions

void waitHandle (HANDLE s)
 

Function Documentation

◆ waitHandle()

void waitHandle ( HANDLE  s)
inline

Wait for a synchronization object to be in the signaled state.

Any thread that creates windows must process messages. A thread that calls WaitForSingelObject with an infinite timeout risks deadlocking the system. MS's solution for this is to use MsgWaitForMultipleObjects to wait on the object, or a new message arriving in the message queue. Some threads create windows indirectly, an example is COM with CoInitialize. Since we can't know if the current thread has a message queue that needs processing, we use MsgWaitForMultipleObjects.

However, with the introduction of the C++ native API in ooRexx 4.0.0, it became possible for external native libraries to attach a thread with an active window procedure to the interpreter. If a wait is done on that thread, here in waitHandle(), PeekMessage() causes non-queued messages to be dispatched, and the window procedure is reentered. This can cause the Rexx program to hang. In addition, in the one known extension where this problem happens, ooDialog, the messages need to be passed to the dialog manager rather than dispatched directly to the window.

For this special case, the thread can explicity ask, through RexxSetProcessMessages(), that messages are not processed during this wait. Thread local storage is used to keep track of a flag signalling this case on a per-thread basis.

Note that MsgWaitForMultipleObjects only returns if a new message is placed in the queue. PeekMessage alters the state of all messages in the queue so that they are no longer 'new.' Once PeekMessage is called, all the messages on the queue need to be processed.

Definition at line 247 of file windows/SysSemaphore.hpp.

References SysSemaphore::noMessageLoop().

Referenced by SysMutex::request(), and SysSemaphore::wait().