Jump to content

DosResumeThread (OS/2 1.x): Difference between revisions

From EDM2
Created page with "==Description== This call restarts a thread previously stopped with a DosSuspendThread call. ==Syntax== <PRE> DosResumeThread (ThreadID) </PRE> ==Parameters== ; Thread..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Description==
This call restarts a thread previously stopped with a [[DosSuspendThread]] call.
This call restarts a thread previously stopped with a DosSuspendThread call.


==Syntax==
==Syntax==
<PRE>
  DosResumeThread (ThreadID)
  DosResumeThread


    (ThreadID)
</PRE>
==Parameters==
==Parameters==
; ThreadID (TID) - input : Thread ID of the resumed thread.
;ThreadID (TID) - input: Thread ID of the resumed thread.


==Return Code==
==Return Code==
rc (USHORT) - return
;rc (USHORT) - return:Return code descriptions are:
*0 NO_ERROR
*309 ERROR_INVALID_THREADID


Return code descriptions are:
==Binding==
===C===
<PRE>
#define INCL_DOSPROCESS


* 0          NO_ERROR
USHORT  rc = DosResumeThread(ThreadID);
* 309        ERROR_INVALID_THREADID
==Remarks==


TID    ThreadID;      /* Thread ID of thread to resume */
USHORT  rc;            /* return code */
</PRE>


==Example Code==
===MASM===
===C Binding===
<PRE>
<PRE>
#define INCL_DOSPROCESS
EXTRN  DosResumeThread:FAR
INCL_DOSPROCESS     EQU 1


USHORT  rc = DosResumeThread(ThreadID);
PUSH  WORD    ThreadID     ;Thread ID
CALL  DosResumeThread


TID              ThreadID;      /* Thread ID of thread to resume */
Returns WORD
</PRE>


USHORT          rc;            /* return code */
==Example==
</PRE>
The following example shows how to suspend and resume execution of a thread within a process. The main thread creates Thread2 and allows it to begin executing. Thread2 iterates through a loop that prints a line and then sleeps, relinquishing its time slice to the main thread. After one iteration by Thread2, the main thread suspends Thread2 and then resumes it. Subsequently, Thread2 completes the remaining three iterations.
The following example shows how to suspend and resume execution of a thread within a process. The main thread creates Thread2 and allows it to begin executing. Thread2 iterates through a loop that prints a line and then sleeps, relinquishing its time slice to the main thread. After one iteration by Thread2, the main thread suspends Thread2 and then resumes it. Subsequently, Thread2 completes the remaining three iterations.  
<PRE>
<PRE>
#define INCL_DOSPROCESS
#define INCL_DOSPROCESS
Line 40: Line 43:
#define  SEGSIZE      4000  /* Number of bytes requested in segment */
#define  SEGSIZE      4000  /* Number of bytes requested in segment */
#define  ALLOCFLAGS    0      /* Segment allocation flags - no sharing */
#define  ALLOCFLAGS    0      /* Segment allocation flags - no sharing */
#define  SLEEPSHORT    5L    /* Sleep interval - 5 milliseconds */
#define  SLEEPSHORT    5L    /* Sleep interval - 5 milliseconds */
#define  SLEEPLONG    75L    /* Sleep interval - 75 milliseconds */
#define  SLEEPLONG    75L    /* Sleep interval - 75 milliseconds */
#define  RETURN_CODE  0      /* Return code for DosExit() */
#define  RETURN_CODE  0      /* Return code for DosExit() */
Line 58: Line 61:
           RETURN_CODE);            /* Return code */
           RETURN_CODE);            /* Return code */
}
}


main()
main()
Line 77: Line 79:


   /** Start Thread2 **/
   /** Start Thread2 **/
   if(!(rc=DosCreateThread((PFNTHREAD) Thread2,   /* Thread address */
   if(!(rc=DosCreateThread((PFNTHREAD) Thread2, /* Thread address */
                       &ThreadID,                 /* Thread ID
                       &ThreadID,             /* Thread ID (returned) */
                                                          (returned) */
                       StackEnd)))  /* End of thread stack */
                       StackEnd)))  /* End of thread stack */
     printf("Thread2 created.\n");
     printf("Thread2 created.\n");
Line 100: Line 101:
</PRE>
</PRE>


===MASM Binding===
[[Category:Dos16]]
<PRE>
EXTRN  DosResumeThread:FAR
INCL_DOSPROCESS    EQU 1
 
PUSH  WORD    ThreadID      ;Thread ID
CALL  DosResumeThread
 
Returns WORD
</PRE>
==Related Functions==
*
 
[[Category:The OS/2 API Project]]

Latest revision as of 06:34, 26 January 2020

This call restarts a thread previously stopped with a DosSuspendThread call.

Syntax

DosResumeThread (ThreadID)

Parameters

ThreadID (TID) - input
Thread ID of the resumed thread.

Return Code

rc (USHORT) - return
Return code descriptions are:
  • 0 NO_ERROR
  • 309 ERROR_INVALID_THREADID

Binding

C

#define INCL_DOSPROCESS

USHORT  rc = DosResumeThread(ThreadID);

TID     ThreadID;      /* Thread ID of thread to resume */
USHORT  rc;            /* return code */

MASM

EXTRN  DosResumeThread:FAR
INCL_DOSPROCESS     EQU 1

PUSH   WORD    ThreadID      ;Thread ID
CALL   DosResumeThread

Returns WORD

Example

The following example shows how to suspend and resume execution of a thread within a process. The main thread creates Thread2 and allows it to begin executing. Thread2 iterates through a loop that prints a line and then sleeps, relinquishing its time slice to the main thread. After one iteration by Thread2, the main thread suspends Thread2 and then resumes it. Subsequently, Thread2 completes the remaining three iterations.

#define INCL_DOSPROCESS

#include <os2.h>

#define   SEGSIZE       4000   /* Number of bytes requested in segment */
#define   ALLOCFLAGS    0      /* Segment allocation flags - no sharing */
#define   SLEEPSHORT    5L     /* Sleep interval -  5 milliseconds */
#define   SLEEPLONG     75L    /* Sleep interval - 75 milliseconds */
#define   RETURN_CODE   0      /* Return code for DosExit() */

VOID APIENTRY Thread2()
{
  USHORT     i;

  /* Loop with four iterations */
  for(i=1; i<5; i++)
  {
    printf("In Thread2, i is now %d\n", i);
    /* Sleep to relinquish time slice to main thread */
    DosSleep(SLEEPSHORT);          /* Sleep interval */
  }
  DosExit(EXIT_THREAD,             /* Action code - end a thread */
          RETURN_CODE);            /* Return code */
}

main()
{
  TID        ThreadID;             /* Thread identification */
  SEL        ThreadStackSel;       /* Segment selector for thread stack */
  PBYTE      StackEnd;             /* Ptr. to end of thread stack */
  USHORT     rc;

  /** Allocate segment for thread stack; make pointer to end of stack. **/
  /**  We must allocate a segment in order to preserve segment
  /**  protection for the thread.  **/

  rc = DosAllocSeg(SEGSIZE,             /* Number of bytes requested */
                   &ThreadStackSel,     /* Segment selector (returned) */
                   ALLOCFLAGS);         /* Allocation flags - no sharing */
  StackEnd = MAKEP(ThreadStackSel, SEGSIZE-1);

  /** Start Thread2 **/
  if(!(rc=DosCreateThread((PFNTHREAD) Thread2, /* Thread address */
                       &ThreadID,              /* Thread ID (returned) */
                       StackEnd)))   /* End of thread stack */
    printf("Thread2 created.\n");

  /* Sleep to relinquish time slice to Thread2 */
  if(!(DosSleep(SLEEPSHORT)))                  /* Sleep interval */
    printf("Slept a little to let Thread2 execute.\n");

  /***** Suspend Thread2, do some work, then resume Thread2 *****/
  if(!(rc=DosSuspendThread(ThreadID)))         /* Thread ID */
    printf("Thread2 SUSPENDED.\n");
  printf("Perform work that will not be interrupted by Thread2.\n");
  if(!(rc=DosResumeThread(ThreadID)))          /* Thread ID */
    printf("Thread2 RESUMED.\n");
  printf("Now we may be interrupted by Thread2.\n");

  /* Sleep to allow Thread2 to complete */
  DosSleep(SLEEPLONG);                         /* Sleep interval */
}