Windows Semaphores In Windows semaphores are declared using
- Slides: 8
Windows Semaphores In Windows, semaphores are declared using the API function Create. Semaphore(). HANDLE Create. Semaphore (Security. Attributes, Initial. Count, Max. Count, Semaphore. ID); ELC 467– 5 Spring 2020 Lecture 6 Page 78
Windows Semaphores In Windows, semaphores are declared using the API function Create. Semaphore(). HANDLE Create. Semaphore (Security. Attributes, Initial. Count, Max. Count, Semaphore. ID); down and up operations are performed using the API functions. Wait. For. Single. Object( ) and Release. Semaphore ( ). ELC 467– 5 Spring 2020 Lecture 6 Page 78
Windows Semaphores In Windows, semaphores are declared using the API function Create. Semaphore(). HANDLE Create. Semaphore (Security. Attributes, Initial. Count, Max. Count, Semaphore. ID); down and up operations are performed using the API functions. Wait. For. Single. Object( ) and Release. Semaphore ( ). Windows provides other synchronization objects such as mutexes and critical sections. ELC 467– 5 Spring 2020 Lecture 6 Page 78
Example 3 DWORD WINAPI Fn 1(LPVOID param) { int i; while(1){ gotoxy(10, 10); i=i+1; printf("Thread 1 %d", i); } } DWORD WINAPI Fn 2(LPVOID param) { int i; while(1){ gotoxy(10, 20); i=i+1; printf("Thread 2 %d", i); } } ELC 467– 5 Spring 2020 Lecture 6 Page 88
Example 3
Example 3 DWORD WINAPI Fn 1(LPVOID param) { int i; while(1){ gotoxy(10, 10); i=i+1; printf("Thread 1 %d", i); } } DWORD WINAPI Fn 2(LPVOID param) { int i; while(1){ gotoxy(10, 20); i=i+1; printf("Thread 2 %d", i); } } ELC 467– 5 Spring 2020 Lecture 6 Page 88
Windows Semaphores main( ) { DWORD Thread. ID 1, Thread. ID 2; char Sem; char c; hsem = Create. Semaphore(NULL, 1, 1, &Sem); HANDLE ht 1 = Create. Thread(NULL, 0, Fn 1, NULL, 0, &Thread. ID 1); HANDLE ht 2 = Create. Thread(NULL, 0, Fn 2, NULL, 0, &Thread. ID 2); while(c != 'e') {c = getche(); } } ELC 467– 5 Spring 2020 Lecture 6 Page 98
Example 4