Skip to content

Commit

Permalink
Add failing test for atomicity of WaitForMultipleEvents w/ waitAll
Browse files Browse the repository at this point in the history
Test contributed by @qwertymaster617, see [0] for associated issue.

[0]: #9
  • Loading branch information
mqudsi committed Nov 17, 2022
1 parent d6afcbc commit 511b79d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ basic_tests = ['ManualResetInitialState',
# Tests that required wfmo
wfmo_tests = [
'WaitTimeoutAllSignalled',
'AtomicWaitAll',
]

test_std = 'c++11'
Expand Down
45 changes: 45 additions & 0 deletions tests/AtomicWaitAll.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifdef _WIN32
#include <Windows.h>
#endif
#include <cassert>
#include <chrono>
#include <iostream>
#include <pevents.h>
#include <thread>

using namespace neosmart;

int main() {
neosmart::neosmart_event_t lEvents[3];
lEvents[0] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset
lEvents[1] = neosmart::CreateEvent( false, false ); // Not Signaled AutoReset
lEvents[2] = neosmart::CreateEvent( false, true ); // Already Signaled AutoReset

// WFMO is non-destructive if a wait-all with any timeout value fails on auto-reset events.
if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) == 0 )
throw std::runtime_error( "Must not be signaled!" );

// FAILS!!
if ( neosmart::WaitForEvent( lEvents[0], 0 ) != 0 )
throw std::runtime_error( "Must be signaled" );

if ( neosmart::WaitForEvent( lEvents[1], 0 ) != WAIT_TIMEOUT )
throw std::runtime_error( "Must not be signaled" );

// FAILS!!
if ( neosmart::WaitForEvent( lEvents[2], 0 ) != 0 )
throw std::runtime_error( "Must be signaled" );


// WFMO is destructive if a wait-all succeeds with any timeout value on auto-reset events.
for ( auto& lEvent : lEvents )
neosmart::SetEvent( lEvent );
if ( neosmart::WaitForMultipleEvents( lEvents, 3, true, 0 ) != 0 ) // OK
throw std::runtime_error( "Must be signaled!" );
for ( auto& lEvent : lEvents )
{
if ( neosmart::WaitForEvent( lEvent, 0 ) != WAIT_TIMEOUT ) // OK
throw std::runtime_error( "Must not be signaled" );
neosmart::DestroyEvent( lEvent );
}
}

0 comments on commit 511b79d

Please sign in to comment.