source: tests/concurrent/signal/block.cfa @ b81fd95

arm-ehjacob/cs343-translationnew-astnew-ast-unique-expr
Last change on this file since b81fd95 was b81fd95, checked in by Michael Brooks <mlbrooks@…>, 15 months ago

Fix bug where pointer and reference types allow unsound initialization and return. Fixes #189

There are two instances of the same basic change, which is using conversionCost instead of castCost for resolving...
A: an InitExpr?, always; affects variable initializations
B: a CastExpr?, for type-system-generated casts only; affects function returns

Changing the behaviour of the typechecker on initialization (do A) and cast (do B):
src/ResolvExpr/AlternativeFinder.cc
src/SynTree/Expression.h
testsinit1.*

Making type of string literal consistent with how C defines it (accommodate A):
src/Parser/ExpressionNode.cc

Making type system happy with incumbent use of void* (accommodate A):
libcfa/src/concurrency/kernel.cfa
libcfa/src/containers/list.hfa
tests/bugs/66.cfa
tests/avltree/avl1.cfa
tests/concurrent/signal/block.cfa
tests/searchsort.cfa

Making type system happy with incumbent plan-9 downcast (accommodate B):
libcfa/src/containers/list.hfa

Fixing previously incorrect constness of declarations (accommodate A):
tests/exceptions/defaults.cfa
libcfa/src/iostream.hfa

Fixing previously incorrect isGenerated classification of casts that desugaring introduces (accommodate B):
src/Concurrency/Keywords.cc
src/Concurrency/Waitfor.cc

Working around trac #207 (revealed by A):
tests/io2.cfa

Working around trac #208 (speculatively created by B):
libcfa/src/bits/locks.hfa
libcfa/src/concurrency/preemption.cfa

Misc:
tests/exceptions/conditional.cfa (accommodate A)

a _msg function for an exception was declared with wrong return type, so it was not compatible for assignment into the vtable instance

libcfa/src/stdlib.hfa

the compiler now prohibits a prior attempt to call a nonexistent realloc overload; calling alloc_align in its place

  • Property mode set to 100644
File size: 3.1 KB
Line 
1//---------------------------------------------------------
2// Barging test
3// Ensures that no barging can occur between :
4//   - the frontend of the signal_block and the signaled thread
5//   - the signaled  threadand the backend of the signal_block
6//---------------------------------------------------------
7
8
9#include <fstream.hfa>
10#include <kernel.hfa>
11#include <monitor.hfa>
12#include <stdlib.hfa>
13#include <thread.hfa>
14#include <time.hfa>
15
16#include "long_tests.hfa"
17
18#ifndef PREEMPTION_RATE
19#define PREEMPTION_RATE 10`ms
20#endif
21
22Duration default_preemption() {
23        return PREEMPTION_RATE;
24}
25
26#ifdef TEST_LONG
27static const unsigned long N = 150_000ul;
28#else
29static const unsigned long N = 5_000ul;
30#endif
31
32enum state_t { WAITED, SIGNAL, BARGE };
33
34monitor global_data_t {
35        $thread * last_thread;
36        $thread * last_signaller;
37};
38
39void ?{} ( global_data_t & this ) {
40        this.last_thread = NULL;
41        this.last_signaller = NULL;
42}
43
44void ^?{} ( global_data_t & mutex this ) {}
45
46global_data_t globalA, globalB;
47
48condition cond;
49
50volatile bool done;
51
52//------------------------------------------------------------------------------
53void wait_op( global_data_t & mutex a, global_data_t & mutex b, unsigned i ) {
54    wait( cond, (uintptr_t)active_thread() );
55
56        yield( random( 10 ) );
57
58        if(a.last_thread != a.last_signaller || b.last_thread != b.last_signaller ) {
59                sout | "ERROR Barging detected, expected" | a.last_signaller | b.last_signaller | "got" | a.last_thread | b.last_thread;
60                abort();
61        }
62
63        a.last_thread = b.last_thread = active_thread();
64
65        yield( random( 10 ) );
66}
67
68thread Waiter {};
69void main( Waiter & this ) {
70        for( int i = 0; TEST(i < N); i++ ) {
71                wait_op( globalA, globalB, i );
72                KICK_WATCHDOG;
73        }
74}
75
76//------------------------------------------------------------------------------
77void signal_op( global_data_t & mutex a, global_data_t & mutex b ) {
78        yield( random( 10 ) );
79
80        [a.last_thread, b.last_thread, a.last_signaller, b.last_signaller] = active_thread();
81
82        if( !is_empty( cond ) ) {
83
84                $thread * next = ( $thread * ) front( cond );
85
86                if( ! signal_block( cond ) ) {
87                        sout | "ERROR expected to be able to signal";
88                        abort();
89                }
90
91                yield( random( 10 ) );
92
93                if(a.last_thread != next || b.last_thread != next) {
94                        sout | "ERROR Barging detected, expected" | next | "got" | a.last_thread | b.last_thread;
95                        abort();
96                }
97        }
98
99}
100
101thread Signaller {};
102void main( Signaller & this ) {
103        while( !done ) {
104                signal_op( globalA, globalB );
105        }
106}
107
108//------------------------------------------------------------------------------
109void barge_op( global_data_t & mutex a ) {
110        a.last_thread = active_thread();
111}
112
113thread Barger {};
114void main( Barger & this ) {
115        for( unsigned i = 0; !done; i++ ) {
116                //Choose some monitor to barge into with some irregular pattern
117                bool choose_a = (i % 13) > (i % 17);
118                if ( choose_a ) barge_op( globalA );
119                else barge_op( globalB );
120        }
121}
122
123//------------------------------------------------------------------------------
124
125int main(int argc, char* argv[]) {
126        srandom( time( NULL ) );
127        done = false;
128        processor p;
129        {
130                Signaller s[4];
131                Barger b[13];
132                sout | "Starting waiters";
133                {
134                        Waiter w[3];
135                }
136                sout | "Waiters done";
137                done = true;
138        }
139}
Note: See TracBrowser for help on using the repository browser.