Revert "xset= can be called on a list and a hash-table"
[sbcl.git] / tools-for-build / os-provides-wakebyaddr-test.c
blob7b3da046d8b13ec9e4ee558808ac4f772b1605c2
1 #include <windows.h>
3 int mutex_word = 0;
4 int expect = 9;
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) {
11 mutex_word = 0;
12 WakeByAddressSingle(&mutex_word);
13 return 0;
16 int main()
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
22 // Try really waiting
23 mutex_word = 9;
24 result = WaitOnAddress(&mutex_word, &expect, 4, 20); // wait 20 millisec
25 // expect a timeout
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 */
32 0, /* flags */
33 0); /* id */
35 hWaker = CreateThread(NULL, 0,
36 waker, 0, /* function and argument */
37 CREATE_SUSPENDED, /* flags */
38 0); /* id */
40 for (;;) {
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
46 ResumeThread(hWaker);
47 WaitForSingleObject(hWaiter, 200); // .2 sec max
48 if (mutex_word == 0) return 104;
49 return 1;