6 #define RW_LOCK_BIAS 0x00100000
7 #define WRITE_LOCK_CMP RW_LOCK_BIAS
9 /** Example implementation of linux rw lock along with 2 thread test
13 std::atomic<int> lock;
16 static inline int write_trylock(rwlock_t *rw)
18 int priorvalue = atomic_fetch_sub(&rw->lock, RW_LOCK_BIAS);
19 if (priorvalue == RW_LOCK_BIAS)
22 atomic_fetch_add(&rw->lock, RW_LOCK_BIAS);
26 static inline void write_unlock(rwlock_t *rw)
28 atomic_fetch_add(&rw->lock, RW_LOCK_BIAS);
35 problemsize if (write_trylock(&mylock)) {write_unlock(&mylock);}
39 int main(int argc, char **argv)
42 mylock.lock = RW_LOCK_BIAS;
44 pthread_create(&t1, 0, &a, NULL);
45 pthread_create(&t2, 0, &a, NULL);