Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include<stdio.h>
- #include<Windows.h>
- #include<process.h>
- HANDLE EventA, EventB, EventC;
- unsigned int _stdcall Print_a(void* pPM) {
- char id = *(char*)pPM;
- for (int i = 0; i < 10; i++) {
- WaitForSingleObject(EventA, INFINITE);
- printf("%c", id);
- SetEvent(EventB);
- }
- }
- unsigned int _stdcall Print_b(void* pPM) {
- char id = *(char*)pPM;
- for (int i = 0; i < 10; i++) {
- WaitForSingleObject(EventB, INFINITE);
- printf("%c", id);
- SetEvent(EventC);
- }
- }
- unsigned int _stdcall Print_c(void* pPM) {
- char id = *(char*)pPM;
- for (int i = 0; i < 10; i++) {
- WaitForSingleObject(EventC, INFINITE);
- printf("%c", id);
- SetEvent(EventA);
- }
- }
- void main() {
- EventA = CreateEvent(NULL, FALSE, TRUE, NULL);
- EventB = CreateEvent(NULL, FALSE, FALSE, NULL);
- EventC = CreateEvent(NULL, FALSE, FALSE, NULL);
- char A = 'A', B = 'B', C = 'C';
- HANDLE a, b, c;
- a = _beginthreadex(NULL, 0, Print_a, &A, 0, NULL);
- b = _beginthreadex(NULL, 0, Print_b, &B, 0, NULL);
- c = _beginthreadex(NULL, 0, Print_c, &C, 0, NULL);
- WaitForSingleObject(a, INFINITE);
- WaitForSingleObject(b, INFINITE);
- WaitForSingleObject(c, INFINITE);
- CloseHandle(EventA);
- CloseHandle(EventB);
- CloseHandle(EventC);
- CloseHandle(a);
- CloseHandle(b);
- CloseHandle(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement