chap6.exercise

chap6.exercise - #include #include

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
#include <windows.h> #include <stdio.h> inline BOOL WaitSucceed(DWORD result, DWORD NumObjects) { // return true if succeeded (WAIT_OBJECT_0 + NumObjects -1)) ); } DWORD WINAPI ChildTh( LPVOID hMutex) {     // covert parameter to mutex handle. ..     HANDLE MutexHandle = (HANDLE) hMutex;     // save this thread's id. ..     DWORD tId = GetCurrentThreadId();     // repeat three times. ..     for (int n =0; n < 3; n++) {         // wait to acquire the mutex. ..         DWORD dwResult = WaitForSingleObject( MutexHandle,  INFINITE);         if (dwResult == WAIT_OBJECT_0) { // Critical Section Begin             // hold the mutex and sleep for one second printf("Thread 0x%08x Executing.\n", tId);             Sleep(1000);               // Critical Section End             ReleaseMutex(MutexHandle);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/22/2011 for the course CMPE 142 at San Jose State.

Page1 / 4

chap6.exercise - #include #include

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online