6 DWORD
waiter(void* arg
) {
7 mutex_word
= expect
= 2;
8 return WaitOnAddress(&mutex_word
, &expect
, 4, 100); // .1 sec max
10 DWORD
waker(void* arg
) {
12 WakeByAddressSingle(&mutex_word
);
18 // Verify that WaitOnAddress returns right away if the mutex word has the wrong value.
19 int result
= WaitOnAddress(&mutex_word
, &expect
, 4, 500); // max = .5 sec
20 if (!result
) return 0; // what? shouldn't be an error to mismatch
24 result
= WaitOnAddress(&mutex_word
, &expect
, 4, 20); // wait 20 millisec
26 if (!(result
== 0 && GetLastError()==ERROR_TIMEOUT
)) return 0;
28 // Simulate a lisp mutex being woken
29 HANDLE hWaiter
, hWaker
;
30 hWaiter
= CreateThread(NULL
, 0,
31 waiter
, 0, /* function and argument */
35 hWaker
= CreateThread(NULL
, 0,
36 waker
, 0, /* function and argument */
37 CREATE_SUSPENDED
, /* flags */
41 // wait for the waiter to place itself into a wait state on the mutex
42 if (mutex_word
== 2) break;
43 Sleep(10); // 10 millisec
45 // Give them some time to rendezvous
47 WaitForSingleObject(hWaiter
, 200); // .2 sec max
48 if (mutex_word
== 0) return 104;