DosResumeThread: Difference between revisions
Appearance
mNo edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
DosResumeThread (tid) | |||
==Parameters== | ==Parameters== | ||
;tid (TID) - input : Thread identifier of the resumed thread. | ;tid ([[TID]]) - input: Thread identifier of the resumed thread. | ||
==Return Code== | ==Return Code== | ||
;ulrc (APIRET) - returns: DosResumeThread returns one of the following values: | |||
DosResumeThread returns one of the following values: | * 0 NO_ERROR | ||
* 0 | * 90 ERROR_NOT_FROZEN | ||
* 90 | *309 ERROR_INVALID_THREADID | ||
* 309 | |||
==Remarks== | ==Remarks== | ||
Line 28: | Line 19: | ||
This example creates a new thread within a process, sleeps for 1 second, suspends the thread for 5 seconds, and then waits for the thread to terminate. | This example creates a new thread within a process, sleeps for 1 second, suspends the thread for 5 seconds, and then waits for the thread to terminate. | ||
Compile this example with MULTITHREAD LIBRARIES. If you are using | Compile this example with MULTITHREAD LIBRARIES. If you are using C Set/2, use the /Gm+ switch. | ||
<PRE> | <PRE> | ||
#define INCL_DOSPROCESS /* Process and thread values */ | #define INCL_DOSPROCESS /* Process and thread values */ | ||
Line 35: | Line 26: | ||
#include <stdio.h> | #include <stdio.h> | ||
void _System CntThreadProc(ULONG LoopMax); | void _System CntThreadProc(ULONG LoopMax); /* Count Thread */ | ||
int main(VOID) { | int main(VOID) { | ||
Line 53: | Line 44: | ||
return 1; | return 1; | ||
} | } | ||
rc = DosSleep (1000); /* Sleep for a second to allow thread to run a bit */ | rc = DosSleep (1000); /* Sleep for a second to allow thread to run a bit */ | ||
Line 61: | Line 51: | ||
return 1; | return 1; | ||
} | } | ||
rc = DosSleep (5000); /* Sleep 5 seconds before resuming the thread */ | rc = DosSleep (5000); /* Sleep 5 seconds before resuming the thread */ | ||
Line 69: | Line 58: | ||
return 1; | return 1; | ||
} | } | ||
rc = DosWaitThread (&tidCntThread, DCWW_WAIT); | rc = DosWaitThread (&tidCntThread, DCWW_WAIT); | ||
if (rc != NO_ERROR) { | if (rc != NO_ERROR) { | ||
printf ("DosWaitThread error : return code = %u\n", rc); | printf ("DosWaitThread error : return code = %u\n", rc); | ||
} | } | ||
printf ("Thread has completed!\n"); | printf ("Thread has completed!\n"); | ||
return NO_ERROR; | return NO_ERROR; | ||
} | } | ||
void _System CntThreadProc(ULONG LoopMax ) /* Count thread */ | void _System CntThreadProc(ULONG LoopMax ) /* Count thread */ | ||
{ | { | ||
ULONG i = 0; /* Loop index */ | ULONG i = 0; /* Loop index */ | ||
for (i=0;i < LoopMax;i++ ) { | for (i=0;i < LoopMax;i++ ) { | ||
printf ("%d\n", i); | printf ("%d\n", i); | ||
} | } | ||
return; | return; | ||
} | } |
Revision as of 15:21, 23 May 2018
Restarts a thread that was previously stopped with DosSuspendThread.
Syntax
DosResumeThread (tid)
Parameters
- tid (TID) - input
- Thread identifier of the resumed thread.
Return Code
- ulrc (APIRET) - returns
- DosResumeThread returns one of the following values:
- 0 NO_ERROR
- 90 ERROR_NOT_FROZEN
- 309 ERROR_INVALID_THREADID
Remarks
If the thread is not in a suspended state when you issue DosResumeThread for it, ERROR_NOT_FROZEN is returned.
Example Code
This example creates a new thread within a process, sleeps for 1 second, suspends the thread for 5 seconds, and then waits for the thread to terminate.
Compile this example with MULTITHREAD LIBRARIES. If you are using C Set/2, use the /Gm+ switch.
#define INCL_DOSPROCESS /* Process and thread values */ #define INCL_DOSERRORS /* DOS error values */ #include <os2.h> #include <stdio.h> void _System CntThreadProc(ULONG LoopMax); /* Count Thread */ int main(VOID) { TID tidCntThread = 0; /* ID returned for newly created thread */ PFNTHREAD pfnCntThread = &CntThreadProc; /* Address of thread program */ ULONG ulThreadParm = 100; /* Parameter to thread routine */ APIRET rc = NO_ERROR; /* Return code */ rc = DosCreateThread(&tidCntThread, /* Thread ID (returned by function) */ pfnCntThread, /* Address of thread program */ ulThreadParm, /* Parameter passed to ThreadProc */ CREATE_READY | /* Thread is ready when created */ STACK_SPARSE, /* Do not pre-commit stack pages */ 8192L); /* Stack size, rounded to page bdy */ if (rc != NO_ERROR) { printf("DosCreateThread error: return code = %u\n", rc); return 1; } rc = DosSleep (1000); /* Sleep for a second to allow thread to run a bit */ rc = DosSuspendThread (tidCntThread); if (rc != NO_ERROR) { printf("DosSuspendThread error: return code = %u\n", rc); return 1; } rc = DosSleep (5000); /* Sleep 5 seconds before resuming the thread */ rc = DosResumeThread (tidCntThread); if (rc != NO_ERROR) { printf("DosResumeThread error: return code = %u\n", rc); return 1; } rc = DosWaitThread (&tidCntThread, DCWW_WAIT); if (rc != NO_ERROR) { printf ("DosWaitThread error : return code = %u\n", rc); } printf ("Thread has completed!\n"); return NO_ERROR; } void _System CntThreadProc(ULONG LoopMax ) /* Count thread */ { ULONG i = 0; /* Loop index */ for (i=0;i < LoopMax;i++ ) { printf ("%d\n", i); } return; }