2015-05-22 18:28:10 +02:00
|
|
|
// Copyright © 2015 Hewlett-Packard Development Company, L.P.
|
|
|
|
|
|
|
|
|
|
#include <winpr/file.h>
|
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
#include <winpr/thread.h>
|
|
|
|
|
|
2018-03-07 12:03:10 +01:00
|
|
|
static DWORD WINAPI thread_func(LPVOID arg)
|
2015-05-22 18:28:10 +02:00
|
|
|
{
|
2021-06-02 15:46:27 +02:00
|
|
|
WINPR_UNUSED(arg);
|
|
|
|
|
|
2015-05-22 18:28:10 +02:00
|
|
|
/* exists of the thread the quickest as possible */
|
|
|
|
|
ExitThread(0);
|
2018-03-07 12:03:10 +01:00
|
|
|
return 0;
|
2015-05-22 18:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TestThreadExitThread(int argc, char* argv[])
|
|
|
|
|
{
|
2026-02-26 14:32:50 +01:00
|
|
|
HANDLE thread = nullptr;
|
2024-01-23 16:49:54 +01:00
|
|
|
DWORD waitResult = 0;
|
2015-05-22 18:28:10 +02:00
|
|
|
|
2021-06-02 15:46:27 +02:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
|
WINPR_UNUSED(argv);
|
|
|
|
|
|
2015-05-22 18:28:10 +02:00
|
|
|
/* FIXME: create some noise to better guaranty the test validity and
|
2019-11-06 15:24:51 +01:00
|
|
|
* decrease the number of loops */
|
2024-01-30 10:25:38 +01:00
|
|
|
for (int i = 0; i < 100; i++)
|
2015-05-22 18:28:10 +02:00
|
|
|
{
|
2026-02-26 14:32:50 +01:00
|
|
|
thread = CreateThread(nullptr, 0, thread_func, nullptr, 0, nullptr);
|
2015-05-22 18:28:10 +02:00
|
|
|
|
|
|
|
|
if (thread == INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
2024-08-26 15:39:33 +02:00
|
|
|
(void)fprintf(stderr, "Got an invalid thread!\n");
|
2015-05-22 18:28:10 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 09:52:03 +02:00
|
|
|
waitResult = WaitForSingleObject(thread, 300);
|
2015-05-22 18:28:10 +02:00
|
|
|
if (waitResult != WAIT_OBJECT_0)
|
|
|
|
|
{
|
|
|
|
|
/* When the thread exits before the internal thread_list
|
|
|
|
|
* was updated, ExitThread() is not able to retrieve the
|
|
|
|
|
* related WINPR_THREAD object and is not able to signal
|
|
|
|
|
* the end of the thread. Therefore WaitForSingleObject
|
|
|
|
|
* never get the signal.
|
|
|
|
|
*/
|
2024-08-26 15:39:33 +02:00
|
|
|
(void)fprintf(
|
|
|
|
|
stderr, "300ms should have been enough for the thread to be in a signaled state\n");
|
2015-05-22 18:28:10 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-16 04:58:36 +02:00
|
|
|
(void)CloseHandle(thread);
|
2015-05-22 18:28:10 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|