thread synchronisation
-
hi,
ich will 2 threads synchronisieren, thread 1 setzt zustände einer statemachine...thread2 reagier auf zustände der statemachine!
Wäre folgendes ne gute Lösung für sowas?Pseudocode: void thread1() { static int i = 0; while(1) { i++; if(i % 7) { Send_Message(setsystemstate(AKTIVE)); } else if(i % 55) { Send_Message(setsystemstate(INAKTIVE)); } Sleep(10); } } void thread2() { while(1) { WaitForSingleObject(systemstate, 10ms); // wenn WaitForSingleObject successfull dann wurde neuer systemstate gesetzt if (waitforsingleobject == successful) systemstate = systemstate_aus_message; // else alten systemsate verwenden if(systemstate == AKTIVE) counter++; else if(systemsate == INAKTIVE); counter--; Sleep(10); } }
-
schau dir mal CRITICAL_SECTION an