msgs12.hlp (Topic list)
WM_SEM1 (1.2)
                                                      Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_WINMESSAGEMGR
 
WM_SEM1
flFlags = LONGFROMMP(mp1);    /* application-defined flags */
 
The WM_SEM1 message is one of four WM_SEM messages that an application can
use to send signals within and between threads. WM_SEM messages can be used
much like an MS OS/2 semaphore. Unlike an MS OS/2 semaphore, however, a
thread waiting for a WM_SEM message can continue to process other messages
instead of blocking until the WM_SEM message is received.
 
A WM_SEM1 message should be posted, not sent, by using the WinPostMsg
function.
 
Parameter  Description
────────────────────────────────────────────────────────────────────────────
 
flFlags    Specifies a 32-bit field that is combined with any previous
           WM_SEM1 messages that have not been retrieved from the message
           queue by using the OR operator. The application determines how
           this parameter is to be used.
 
Return Value
 
An application should return zero if it processes this message.
 
Comments
 
A WM_SEM1 message is quite fast, having a higher priority than other
messages. The following list shows the message priority of the WM_SEM1
message in relation to other messages (from highest to lowest):
 
     WM_SEM1
     Any message posted using the WinPostMsg function or any input message
     not listed here.
     WM_SEM2
     WM_TIMER
     WM_SEM3
     WM_PAINT
     WM_SEM4
 
WM_SEM1 messages are handled differently by the system than other messages.
They can be used even if a message queue is full. When a WM_SEM1 message is
posted, the system combines each message queue's WM_SEM1 messages into one
message by combining the flFlags parameter with the message queue's previous
WM_SEM1 flFlags parameter. The flFlags parameter is cleared whenever the
WM_SEM1 message is retrieved.
 
The application must determine how the flFlags field is to be used. An
application might set flag bits to indicate certain actions to be taken by
the receiver of the WM_SEM1 message, or it might set a bit to indicate who
is actually posting the WM_SEM1 message.
 
Example
 
In this example, a thread notifies the client window that the thread is
about to terminate. It sends the constant THREAD3 as the flFlags parameter
so that when the client window receives the message, it can tell which
thread terminated.
 
#define THREAD1 1     /* bit #1 */
#define THREAD2 2     /* bit #2 */
#define THREAD3 4     /* bit #3 */
VOID FAR Thread3() {
    .
    .
    .
    WinPostMsg(hwndClient, WM_SEM1, (MPARAM) THREAD3, 0);
    DosExit(EXIT_THREAD, 0);
}
 
See Also
 
WinPostMsg