#include #include "locks.hfa" #include "alarm.hfa" #include #include #include "kernel.cfa" multiple_acquisition_lock m; condition_variable( multiple_acquisition_lock ) c_m; semaphore s; // used for barrier like behaviour const unsigned int NoOfTimes = 20; void block() { if (s.count == 0) { P(s); } else { V(s); } } thread T1 {}; void main( T1 & this ) { lock(m); wait( c_m, m, 1`s ); // printf("Thread: %p timedout\n", active_thread()); // removed since can't expect non deterministic output block(); // Test calls which occur increasingly close to timeout value. for ( unsigned int i = 0; i < NoOfTimes + 3; i += 1 ) { if ( wait( c_m, m, 1`s ) ) { // printf("Thread: %p signalled\n", active_thread()); // removed since can't expect non deterministic output } else { // printf("Thread: %p timedout\n", active_thread()); // removed since can't expect non deterministic output } // if block(); } // for } thread T2 {}; void main( T2 & this ) { block(); // Test calls which occur increasingly close to timeout value. sleep( 100000000`ns ); notify_one(c_m); block(); sleep( 500000000`ns ); notify_one(c_m); block(); sleep( 900000000`ns ); notify_one(c_m); block(); for ( unsigned int i = 0; i < NoOfTimes; i += 1 ) { sleep( 999700000`ns ); notify_one(c_m); block(); } // for } int main() { processor p[2]; printf("Start Test 1: surface testing condition variable timeout routines\n"); wait( c_m, 1`ns ); // bool wait( condition_variable(L) & this, Duration duration ); wait( c_m, 10, 1`ns ); // bool wait( condition_variable(L) & this, uintptr_t info, Duration duration ); wait( c_m, __kernel_get_time() + 1`ns ); // bool wait( condition_variable(L) & this, Time time ); wait( c_m, 10, __kernel_get_time() + 1`ns ); // bool wait( condition_variable(L) & this, uintptr_t info, Time time ); lock(m); wait( c_m, m, 1`ns ); unlock(m); // bool wait( condition_variable(L) & this, L & l, Duration duration ); lock(m); wait( c_m, m, 10, 1`ns ); unlock(m); // bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration ); lock(m); wait( c_m, m, __kernel_get_time() + 1`ns ); unlock(m); // bool wait( condition_variable(L) & this, L & l, Time time ); lock(m); wait( c_m, m, 10, __kernel_get_time() + 1`ns ); unlock(m); // bool wait( condition_variable(L) & this, L & l, uintptr_t info, Time time ); printf("Done Test 1\n"); printf("Start Test 2: testing timeout vs signalling with varying timeout durations\n"); s{ 0 }; { T1 t1; T2 t2; } printf("Done Test 2\n"); }