DosSuspendThread and DosResumeThread are used to temporarily suspend the execution of a thread when it is not needed and resume execution when the thread is needed.
These functions are best used when it is necessary for a process to temporarily suspend execution of a thread that is in the middle of a task. For example, consider a thread that opens and reads files from a disk. If other threads in the process do not require input from these files, the process can suspend execution of the thread so that OS/2 does not needlessly grant control to it.
The specified thread might not be suspended immediately if it has some system resources locked that must be freed first. However, the thread is not permitted to execute further application program instructions until a corresponding DosResumeThread is called.
A thread can only suspend another thread that is within its process.
DosResumeThread is used to enable the suspended thread to resume execution.
The following code fragment temporarily suspends the execution of another thread within the same process. A subsequent call to DosResumeThread restarts the suspended thread. Assume that the thread identifier of the target thread has been placed int ThreadID already.
#define INCL_DOSPROCESS /* Process and thread values */ #include <os2.h> #include <stdio.h> TID tidThreadID; /* Thread identifier */ APIRET ulrc; /* Return code */ ulrc = DosSuspendThread(tidThreadID); if (ulrc != 0) { printf("DosSuspendThread error: return code = %ld", ulrc); return; } ulrc = DosResumeThread(tidThreadID); if (ulrc != 0) { printf("DosResumeThread error: return code = %ld", ulrc); return; }