Microsoft KB Archive/62501

PRB: DosTimerAsync & DosTimerStart Require CSEM_PUBLIC PSS ID Number: Q62501 Article last modified on 08-13-1991 PSS database name: O_Os2SDK

1.00 1.10 1.21 1.30

OS/2

Summary:

SYMPTOMS If DosCreateSem is used to create a semaphore with the CSEM_PRIVATE option, the semaphore can only be modified by the threads belonging to the process that made the call. Since DosTimerAsync and DosTimerStart execute with a system thread (a thread that belongs to the system and not to the process that made the call), these functions cannot modify the thread created with CSEM_PRIVATE.

CAUSE The documentation for DosTimerAsync and DosTimerStart states that hsem must be a handle to a system semaphore. It also states that the handle must be created with DosCreateSem. However, the documentation fails to state that DosCreateSem must be used with CSEM_PUBLIC and not CSEM_PRIVATE.

Also, the documentation for DosTimerAsync and DosTimerStart does not mention that DosTimerAsync and DosTimerStart use a system thread.

Microsoft has confirmed that the information described above should be included on page 156 [DosTimerAsync] and page 157 [DosTimerStart] of the “Microsoft Operating System/2 Programmer’s Reference Volume 3” for version 1.10.

STATUS We will post new information here when the documentation has been updated to include this information.

More Information:

This situation occurs because DosTimerAsync and DosTimerStart are asynchronous functions. They are different than DosSleep. DosSleep will not return until the specified time has elapsed. DosTimerAsync and DosTimerStart return control immediately to the process, and use a system thread to wait for the time to elapse and clear the semaphore. Please note that DosTimerAsync and DosTimerStart use a system thread, and do not create another thread that belongs to the process owning the semaphore. Therefore, unless the semaphore was created as CSEM_PUBLIC, the system thread used by DosTimerAsync or DosTimerStart cannot clear the semaphore after the time has elapsed.

In the code listed below, DosSemWait will return only if DosCreateSem uses CSEM_PUBLIC. If that parameter is changed to be CSEM_PRIVATE, DosSemWait will not return.


 * 1) define INCL_DOS #define INCL_DOSSEMAPHORES #define INCL_DOSDATETIME #include 

void main { HSYSSEM hsem; HTIMER timer;

DosCreateSem( CSEM_PUBLIC, &hsem, “\sem\test.sem”); DosSemSet( hsem ); DosTimerAsync( 500L, hsem, &timer ); DosSemWait( hsem, SEM_INDEFINITE_WAIT ); }

Copyright Microsoft Corporation 1991.