It would be nice if there were condition variables (CONDITION_VARIABLE) support in win32 headers and import libraries. Condition variables are supported in Windows Vista and newer.
API info at http://msdn.microsoft.com/en-us/library/ms682052%28VS.85%29.aspx
This feature request is related with this other request implemented and closed but for MinGW-w64: https://sourceforge.net/p/mingw-w64/feature-requests/29/
Looks like the necessary hooks are already present in
libkernel32.a:so, the missing piece of the jigsaw is appropriately guarded declarations in
include/winbase.h. Unfortunately, MSDN doesn't seem to give us any indication of howCONDITION_VARIABLEshould betypedef'd, but an opaque pointer may suffice, in which case we could add:(Don't ask me to explain the BOOL vs. BOOLEAN return value discrepancies ... it's just another example of Microsoft's ineptitude in providing a consistent API design).
If you paste that into your source, (after including
<windows.h>, and bracketting it in_BEGIN_C_DECLS..._END_C_DECLS, if you need it to compile asC++), are you able to achieve your objective?Last edit: Keith Marshall 2016-09-15
If you cannot be bothered to test, and comment as requested, I will reject this request! I'll give you until the end of February-2017, to furnish a suitable response.
Reopened, as pending, following an expression of interest by another user.
In my current project the support for CONDITION_VARIABLEs would be of great help. I added the above suggested codelines to my project and it worked.
I also wrote a test-programm (attached to this post) which spawns 4 threads and syncs via a mutex (CRITICAL_SECTION) and a condition (CONDITION_VARIABLE).
Thanks. The test case was useful, although it did raise one issue of coding style ... never use mixed case when referring to system header files:
#include <Windows.h>becomes a fatal error when the file system is case-sensitive, (as it is for my Linux hosted cross development environment). That aside, I applied [94803e] and [5a6bfc], and reduced your test case to:Obviously, that fails when run on my WinXP VM, (because the
CONDITION_VARIABLEAPI is unsupported), but on a Win7 VM it produces:which (I think) represents a successful outcome, for the case of condition variables used to synchronize access to critical sections; I guess we should also try to adapt the test, to cover the case of synchronization across slim reader/writer locks.
Related
Commit: [5a6bfc]
Commit: [94803e]
Last edit: Keith Marshall 2017-06-03
In reply to private e-mail:
On 16/06/17 13:39, Johann Baumann wrote:
No problem, but please keep all relevant correspondence on the
tracker ticket; it tends to get lost otherwise.
Thanks. Ultimately I'd like to implement it within a GNU autotest
framework; that requires all output to stdout and stderr to be 100%
deterministically reproducible. I suspect that some of the thread
start-up messages, as currently implemented, may not comply.
Thanks. Once again, please attach it to the ticket.
Last edit: Keith Marshall 2017-06-16
I rewrote 'test.c' to give a deterministic output. Furthermore i wrote a super-silly 'test2.c' to
check the SRWLocks. Both work and give the desired result :)
Thanks! I will take a look, but it may be a few weeks before I can get around to it. In the meantime, I may go ahead and include the implementation in an interim release, albeit lacking a formal test case.
The proposed implementation is now included in the recently published WSL-5.0.1; the accompanying testsuite component remains outstanding.