define the os2 threads codethe sample program in


Define the OS/2 threads code

The sample program in Listing is very similar to the NetWare example. OS/2 commands are substituted for the pseudocode commands controlling thread creation and execution.

Listing

Void WorkerThread(ULONG userID);

#define SLEEP_INTERVAL (ULONG) 50

void AcceptRegisterationRequests( )

{

   int userID, threadID ;

   do{

        ......

        WaitforClientRegistration( )

        RegisterClient()

        UserID = RegisterAsUser ( )

        DocCreateThread(&threadID,WorkerThread, userID, 0, 8192)

        ......

     } while (FOREVER)

   }

   Void WorkerThread(ULONG userID);

   {

  do{

          DosSleep(SLEEP_INTERVAL);

                   if (WorkAvailable) {

    Process Request ( )

    Send Response ( )

   }

  } while (CLENT_CONNECTED)

  DosExit(EXIT_THREAD,0);

 }

Listing : OS/2 threads code example  Upon successful registration, an OS/2 thread is started with the CreateThread(  ) command. The function WorkerThread( ) begins asynchronous execution and loops at specified intervals looking for work to perform. The intervals are created by the DosSleep ( ) function call and  will allow  the thread to periodically  poll for available work.When the client requests closure of the connection or an error occurs, the DosExit( ) function will be performed to exit the current worker thread.

Request for Solution File

Ask an Expert for Answer!!
Operating System: define the os2 threads codethe sample program in
Reference No:- TGS0289655

Expected delivery within 24 Hours