Skip to content

Commit e7801e7

Browse files
committed
Add failing test for atomicity of WaitForMultipleEvents w/ waitAll
Test contributed by @qwertymaster617, see [0] for associated issue. [0]: #9
1 parent 0bc424c commit e7801e7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ basic_tests = ['ManualResetInitialState',
3232
# Tests that required wfmo
3333
wfmo_tests = [
3434
'WaitTimeoutAllSignalled',
35+
'AtomicWaitAll',
3536
]
3637

3738
test_std = 'c++11'

tests/AtomicWaitAll.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifdef _WIN32
2+
#include <Windows.h>
3+
#endif
4+
#include <cassert>
5+
#include <chrono>
6+
#include <iostream>
7+
#include <pevents.h>
8+
#include <thread>
9+
10+
using namespace neosmart;
11+
12+
int main() {
13+
neosmart::neosmart_event_t lEvents[3];
14+
lEvents[0] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset
15+
lEvents[1] = neosmart::CreateEvent( false, false ); // Not Signaled AutoReset
16+
lEvents[2] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset
17+
18+
// WFMO is non-destructive if a wait-all with any timeout value fails on auto-reset events.
19+
if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) == 0 )
20+
throw std::runtime_error( "Must not be signaled!" );
21+
22+
// FAILS!!
23+
if ( neosmart::WaitForEvent( lEvents[0], 0 ) != 0 )
24+
throw std::runtime_error( "Must be signaled" );
25+
26+
if ( neosmart::WaitForEvent( lEvents[1], 0 ) != WAIT_TIMEOUT )
27+
throw std::runtime_error( "Must not be signaled" );
28+
29+
// FAILS!!
30+
if ( neosmart::WaitForEvent( lEvents[2], 0 ) != 0 )
31+
throw std::runtime_error( "Must be signaled" );
32+
33+
34+
// WFMO is destructive if a wait-all succeeds with any timeout value on auto-reset events.
35+
for ( auto& lEvent : lEvents )
36+
neosmart::SetEvent( lEvent );
37+
if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) != 0 ) // OK
38+
throw std::runtime_error( "Must be signaled!" );
39+
for ( auto& lEvent : lEvents )
40+
{
41+
if ( neosmart::WaitForEvent( lEvent, 0 ) != WAIT_TIMEOUT ) // OK
42+
throw std::runtime_error( "Must not be signaled" );
43+
neosmart::DestroyEvent( lEvent );
44+
}
45+
}

0 commit comments

Comments
 (0)