source: CIVL/examples/fairness/fair5.cvl

main
Last change on this file was 3cdf8a2, checked in by Stephen Siegel <siegel@…>, 3 years ago

Fixed bug in SimpleEnablerWorker in which the dependency set for a contractless atomic function was not being computed correctly. Now everything is slower.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5856 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 833 bytes
Line 
1/* This program has a non-terminating fair execution */
2// #pragma CIVL ACSL
3#include <stdlib.h>
4
5typedef struct _lock {
6 $proc owner;
7} Lock;
8
9Lock* lock_create() {
10 Lock* result = (Lock*) malloc(sizeof(Lock));
11 result->owner = $proc_null;
12 return result;
13}
14
15void lock_destroy(Lock * l) {
16 free(l);
17}
18
19/*@ depends_on \access(l); */
20$atomic_f void lock_acquire(Lock* l) {
21 $when (l->owner == $proc_null)
22 l->owner = $self;
23}
24
25/*@ depends_on \access(l); */
26$atomic_f void lock_release(Lock* l) {
27 l->owner = $proc_null;
28}
29
30Lock * lock = lock_create();
31int x=1;
32
33void f1() {
34 while (x) {
35 lock_acquire(lock);
36 lock_release(lock);
37 }
38}
39
40void f2() {
41 lock_acquire(lock);
42 x=0;
43 lock_release(lock);
44}
45
46int main() {
47 $proc p1 = $spawn f1();
48 $proc p2 = $spawn f2();
49 $wait(p1);
50 $wait(p2);
51 lock_destroy(lock);
52}
Note: See TracBrowser for help on using the repository browser.