#include <cdsannotate.h>
#include <specannotation.h>
#include <model_memory.h>
+#include "common.h"
#include "librace.h"
@Happens_before:
# Since commit_point_set has no ID attached, A -> B means that for any B,
# the previous A happens before B.
+ Read_Unlock -> Read_Lock
+ Read_Unlock -> Write_Lock
+ Read_Unlock -> Write_Trylock(HB_Write_Trylock_Succ)
+ Read_Unlock -> Read_Trylock(HB_Read_Trylock_Succ)
+
Write_Unlock -> Write_Lock
Write_Unlock -> Write_Trylock(HB_Write_Trylock_Succ)
@Interface: Write_Trylock
@Commit_point_set:
Write_Trylock_Succ_Point | Write_Trylock_Fail_Point
- @Condition:
- !writer_lock_acquired && reader_lock_cnt == 0
@HB_condition:
HB_Write_Trylock_Succ :: __RET__ == 1
@Action:
- if (__COND_SAT__)
+ if (__RET__ == 1)
writer_lock_acquired = true;
- @Post_check:
- __COND_SAT__ ? __RET__ == 1 : __RET__ == 0
@End
*/
static inline int write_trylock(rwlock_t *rw)
{
int priorvalue = atomic_fetch_sub_explicit(&rw->lock, RW_LOCK_BIAS, memory_order_acquire);
+ //model_print("write_trylock: priorvalue: %d\n", priorvalue);
/**
@Begin
@Potential_commit_point_define: true
for(i = 0; i < 2; i++) {
if ((i % 2) == 0) {
read_lock(&mylock);
- load_32(&shareddata);
+ //load_32(&shareddata);
+ printf("%d\n", shareddata);
read_unlock(&mylock);
} else {
write_lock(&mylock);
- store_32(&shareddata,(unsigned int)i);
+ //store_32(&shareddata,(unsigned int)i);
+ shareddata = 47;
write_unlock(&mylock);
}
}
}
+static void b(void *obj)
+{
+ int i;
+ for(i = 0; i < 2; i++) {
+ if ((i % 2) == 0) {
+ if (read_trylock(&mylock) == 1) {
+ printf("%d\n", shareddata);
+ read_unlock(&mylock);
+ }
+ } else {
+ if (write_trylock(&mylock) == 1) {
+ shareddata = 47;
+ write_unlock(&mylock);
+ }
+ }
+ }
+}
+
int user_main(int argc, char **argv)
{
/**
atomic_init(&mylock.lock, RW_LOCK_BIAS);
thrd_create(&t1, (thrd_start_t)&a, NULL);
- thrd_create(&t2, (thrd_start_t)&a, NULL);
+ thrd_create(&t2, (thrd_start_t)&b, NULL);
thrd_join(t1);
thrd_join(t2);