source: tests/unified_locking/timeout_lock.cfa @ f621e43f

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f621e43f was 9bb9545b, checked in by caparsons <caparson@…>, 3 years ago

changed back time length

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include <stdio.h>
2#include "locks.hfa"
3#include "alarm.hfa"
4#include <stdlib.hfa>
5#include <thread.hfa>
6#include "kernel.cfa"
7
8multiple_acquisition_lock m;
9condition_variable( multiple_acquisition_lock ) c_m;
10
11semaphore s; // used for barrier like behaviour
12
13const unsigned int NoOfTimes = 20;
14
15void block() {
16        if (s.count == 0) {
17                P(s);
18        } else {
19                V(s);
20        }
21}
22
23thread T1 {};
24
25void main( T1 & this ) {
26        lock(m);
27        wait( c_m, m, 1`s );
28        // printf("Thread: %p timedout\n", active_thread()); // removed since can't expect non deterministic output
29
30        block();
31
32        // Test calls which occur increasingly close to timeout value.
33
34        for ( unsigned int i = 0; i < NoOfTimes + 3; i += 1 ) {
35            if ( wait( c_m, m, 1`s ) ) {
36                        // printf("Thread: %p signalled\n", active_thread()); // removed since can't expect non deterministic output
37            } else {
38                        // printf("Thread: %p timedout\n", active_thread()); // removed since can't expect non deterministic output
39            } // if
40
41            block();
42        } // for
43}
44
45
46thread T2 {};
47
48void main( T2 & this ) {
49        block();
50
51        // Test calls which occur increasingly close to timeout value.
52
53        sleep( 100000000`ns );
54        notify_one(c_m);
55        block();
56
57        sleep( 500000000`ns );
58        notify_one(c_m);
59        block();
60
61        sleep( 900000000`ns );
62        notify_one(c_m);
63        block();
64
65        for ( unsigned int i = 0; i < NoOfTimes; i += 1 ) {
66            sleep( 999700000`ns );
67                notify_one(c_m);
68            block();
69        } // for
70}
71
72int main() {
73        processor p[2];
74        printf("Start Test 1: surface testing condition variable timeout routines\n");
75        wait( c_m, 1`ns );                                                                                                              // bool wait( condition_variable(L) & this, Duration duration );       
76        wait( c_m, 10, 1`ns );                                                                                                  // bool wait( condition_variable(L) & this, uintptr_t info, Duration duration );
77        wait( c_m, __kernel_get_time() + 1`ns );                                                                // bool wait( condition_variable(L) & this, Time time );
78        wait( c_m, 10, __kernel_get_time() + 1`ns );                                                    // bool wait( condition_variable(L) & this, uintptr_t info, Time time );
79        lock(m); wait( c_m, m, 1`ns ); unlock(m);                                                               // bool wait( condition_variable(L) & this, L & l, Duration duration );
80        lock(m); wait( c_m, m, 10, 1`ns ); unlock(m);                                                   // bool wait( condition_variable(L) & this, L & l, uintptr_t info, Duration duration );
81        lock(m); wait( c_m, m, __kernel_get_time() + 1`ns ); unlock(m);                 // bool wait( condition_variable(L) & this, L & l, Time time );
82        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 );
83        printf("Done Test 1\n");
84
85        printf("Start Test 2: testing timeout vs signalling with varying timeout durations\n");
86        s{ 0 };
87        {
88                T1 t1;
89                T2 t2;
90        }
91        printf("Done Test 2\n");
92}
Note: See TracBrowser for help on using the repository browser.