Suspending Threads

An application can use DosSleep to suspend operation of a thread for a specified interval. The system waits the specified number of milliseconds (subject to the round-off error just discussed) before returning control to the application. Because a sleeping application yields execution control to the system, the system can execute other processes or threads while the application sleeps.

The following code fragment shows how to suspend the calling thread for one minute:

    #define INCL_DOSPROCESS   /* Process and thread values */
    #include <os2.h>
    #include <stdio.h>

    ULONG   ulTimeInterval;   /* Interval in milliseconds  */
    APIRET  ulrc;             /* Return code               */

    ulTimeInterval = 60000;

    ulrc = DosSleep(ulTimeInterval);

    if (ulrc != 0) {
        printf("DosSleep error: return code = %ld",
               ulrc);
        return;
    }

See Suspending the Current Thread for more information on DosSleep.


[Back: About Timers]
[Next: Asynchronous Timers]