// S : tags threads c++ weakmem pso todo $TAGS // S : expect --result valid // S : cc -o test.bc $CC_OPT $file // S : verify -o nofail:malloc --relaxed-memory pso:5 $V_OPT test.bc // N : V : CC_OPT : V_OPT : TAGS : RESULT // V : dynamic-init : -DSTATIC_INIT=0 : : : valid // V : static-init : -DSTATIC_INIT=1 : : : valid #include #include #include #ifndef STATIC_INIT #define STATIC_INIT 1 #endif std::atomic< int > x, y; int rx, ry; #if STATIC_INIT pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; #else pthread_mutex_t mtx; #endif int main() { __sync_synchronize(); #if !STATIC_INIT pthread_mutex_init( &mtx, nullptr ); #endif pthread_t t; pthread_create( &t, nullptr, []( void * ) -> void * { pthread_mutex_lock( &mtx ); x.store( 1, std::memory_order_relaxed ); y.store( 1, std::memory_order_relaxed ); pthread_mutex_unlock( &mtx ); return nullptr; }, nullptr ); pthread_mutex_lock( &mtx ); ry = y.load( std::memory_order_relaxed ); rx = x.load( std::memory_order_relaxed ); pthread_mutex_unlock( &mtx ); pthread_join( t, nullptr ); assert( ry != 1 || rx == 1 ); }