static PyObject * RWLock_func_tryrdlock(RWLock *self) { int r; RAISE_IF_NOT_INITIALIZED(self, NULL); Py_BEGIN_ALLOW_THREADS r = uv_rwlock_tryrdlock(&self->uv_rwlock); Py_END_ALLOW_THREADS return PyBool_FromLong((long)(r == 0)); }
// https://github.com/thlorenz/libuv-dox/blob/master/methods.md#uv_rwlock_rdlock void reader_entry(void *n) { int r; int num = *(int*)n; for (int i = 0; i < ROUNDS; i++) { do { r = uv_rwlock_tryrdlock(&numlock); // implementation ./src/unix/thread.c aborts the process unless return value was EBUSY or EAGAIN // so checking here again is redundant and mainly done for documentation // fact is that the only r we'd ever get would be EBUSY or EAGAIN (negated) if (r && r != -EBUSY && r != -EAGAIN) ERROR("obtaining read lock", r); } while(r); fprintf(stderr, "Reader %d: aquired lock and shared num = %d\n", num, shared_num); uv_rwlock_rdunlock(&numlock); fprintf(stderr, "Reader %d: released lock\n", num); } uv_barrier_wait(&blocker); }