diff options
Diffstat (limited to 'src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c')
-rw-r--r-- | src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c new file mode 100644 index 0000000000..15d0a386d1 --- /dev/null +++ b/src/pal/tests/palsuite/threading/WaitForMultipleObjectsEx/test4/test4.c @@ -0,0 +1,101 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*===================================================================== +** +** Source: test4.c +** +** Purpose: Tests that waiting on an abandonded mutex will a return +** WAIT_ABANDONED_0. Does this by creating a child thread that +** acquires the mutex and exits. +** +** +**===================================================================*/ + +#include <palsuite.h> + + +const int ChildThreadWaitTime = 1000; +const int ParentDelayTime = 2000; + +DWORD PALAPI AbandoningProc(LPVOID lpParameter); + +int __cdecl main( int argc, char **argv ) +{ + HANDLE Mutex; + HANDLE hThread = 0; + DWORD dwThreadId = 0; + int ret; + + if (0 != (PAL_Initialize(argc, argv))) + { + return FAIL; + } + + Mutex = CreateMutexW(NULL, FALSE, NULL); + if (Mutex == NULL) + { + Fail("Unable to create the mutex. GetLastError returned %d\n", + GetLastError()); + } + + hThread = CreateThread( NULL, + 0, + (LPTHREAD_START_ROUTINE)AbandoningProc, + (LPVOID) Mutex, + 0, + &dwThreadId); + + if (hThread == NULL) + { + Fail("ERROR: Was not able to create the thread to test!\n" + "GetLastError returned %d\n", GetLastError()); + } + + Sleep(ParentDelayTime); + + ret = WaitForMultipleObjectsEx(1, &Mutex, FALSE, INFINITE, FALSE); + if (ret != WAIT_ABANDONED_0) + { + Fail("Expected WaitForMultipleObjectsEx to return WAIT_ABANDONED_0\n" + "Got %d\n", ret); + } + + ReleaseMutex(Mutex); + if (!CloseHandle(Mutex)) + { + Fail("CloseHandle on the mutex failed!\n"); + } + + if (!CloseHandle(hThread)) + { + Fail("CloseHandle on the thread failed!\n"); + } + + PAL_Terminate(); + return PASS; +} + +/* + * Entry Point for child thread. Acquries a mutex and exit's without + * releasing it. + */ +DWORD PALAPI AbandoningProc(LPVOID lpParameter) +{ + HANDLE Mutex; + DWORD ret; + + Mutex = (HANDLE) lpParameter; + + Sleep(ChildThreadWaitTime); + + ret = WaitForSingleObject(Mutex, 0); + if (ret != WAIT_OBJECT_0) + { + Fail("Expected the WaitForSingleObject call on the mutex to succeed\n" + "Expected return of WAIT_OBJECT_0, got %d\n", ret); + } + + return 0; +} |