Hi,
Recently I thought I found a use-case for CreateThread(CREATE_SUSPENDED). The idiom is to get the thread handle before the thread starts a life on its own.
I looked at the kernel tests, http://source.winehq.org/source/dlls/kernel32/tests/thread.c#L460
However, both invocations with CREATE_SUSPENDED actually test the pair CreateThread + SuspendThread. The tests do not prove that CREATE_SUSPENDED works! They only prove that the suspend counter and perhaps SuspendThread work.
a) Does Wine not support CREATE_SUSPENDED, so that the tests do the best they can? In such a case, a WARN("ignoring SUSPENDED flag, beware of race conditions\n") would be appropriate.
or b) CREATE_SUSPENDED is fully supported on all platforms. Then the tests need some refinement.
Thank you, Jörg Höhle
I'm pretty sure CREATE_SUSPENDED works. It's such a basic thing that would cause many race conditions if it did not, including in parts of Wine that use it and in the test you just linked.
If the new thread were not initially suspended, it would be possible for the thread to return between the initial CreateThread call and the following SuspendThread call. This would cause the first WaitForSingleObject to succeed and the test to fail.
I guess you could change the test to include a wait before the first SuspendThread call, but given that there probably aren't any broken implementations that this would specifically catch (and those implementations would already fail sometimes), I don't see the point.
Am 27.09.2012 09:13, schrieb Joerg-Cyril.Hoehle@t-systems.com:
Hi,
Recently I thought I found a use-case for CreateThread(CREATE_SUSPENDED). The idiom is to get the thread handle before the thread starts a life on its own.
I looked at the kernel tests, http://source.winehq.org/source/dlls/kernel32/tests/thread.c#L460
However, both invocations with CREATE_SUSPENDED actually test the pair CreateThread + SuspendThread. The tests do not prove that CREATE_SUSPENDED works! They only prove that the suspend counter and perhaps SuspendThread work.
a) Does Wine not support CREATE_SUSPENDED, so that the tests do the best they can? In such a case, a WARN("ignoring SUSPENDED flag, beware of race conditions\n") would be appropriate.
or b) CREATE_SUSPENDED is fully supported on all platforms. Then the tests need some refinement.
Why did you only had a look at the tests? I checked the source in 30 seconds and answered the question for me: CREATE_SUSPENDED is an essential part of the CreateThread Implementation. Anyway, more tests are always welcome.