Ignore:
Timestamp:
Jul 26, 2021, 2:42:34 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0a061c0
Parents:
c86ee4c (diff), 98233b3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/unified_locking/fast.cfa

    rc86ee4c rd83b266  
    1 #include <fstream.hfa>
    21#include <locks.hfa>
    3 #include <thread.hfa>
    42
    5 const unsigned int num_times = 50;
    6 
    7 struct MutexObj {
    8         fast_lock l;
    9         thread$ * id;
    10         uint32_t sum;
    11 };
    12 
    13 MutexObj mo;
    14 
    15 void trash() {
    16         unsigned t[100];
    17         for(i; 100) {
    18                 t[i] = 0xDEADBEEF;
    19         }
    20 }
    21 
    22 uint32_t cs() {
    23         thread$ * me = active_thread();
    24         uint32_t value;
    25         lock(mo.l);
    26         {
    27                 uint32_t tsum = mo.sum;
    28                 mo.id = me;
    29                 yield(random(5));
    30                 value = ((uint32_t)random()) ^ ((uint32_t)me);
    31                 if(mo.id != me) sout | "Intruder!";
    32                 mo.sum = tsum + value;
    33         }
    34         unlock(mo.l);
    35         return value;
    36 }
    37 
    38 thread LockCheck {
    39         uint32_t sum;
    40 };
    41 
    42 void main(LockCheck & this) {
    43         this.sum = 0;
    44         for(num_times) {
    45                 trash();
    46                 this.sum += cs();
    47                 trash();
    48                 yield(random(10));
    49         }
    50 }
     3#define LOCK fast_lock
     4#include "mutex_test.hfa"
    515
    526int main() {
    53         uint32_t sum = -32;
    54         mo.sum = -32;
    55         processor p[2];
    56         sout | "Starting";
    57         {
    58                 LockCheck checkers[13];
    59                 for(i;13) {
    60                         sum += join(checkers[i]).sum;
    61                 }
    62         }
    63         sout | "Done!";
    64         if(sum == mo.sum) sout | "Match!";
    65         else sout | "No Match!" | sum | "vs" | mo.sum;
     7    test();
    668}
Note: See TracChangeset for help on using the changeset viewer.