rwlock

Making pthread_rwlock_wrlock recursive

断了今生、忘了曾经 提交于 2019-12-10 05:26:56
问题 I have a problem regarding the behaviour of the pthread function pthread_rwlock_wrlock. The specification linked above states that when one thread has locked the lock for writing and the same thread locks it again, it results in undefined behaviour (I could actually observe this in that on x86 Linux calling this function is a noop and on PowerPC Linux it stalls the thread). The behaviour I need would be a read write lock that has the following characteristics: read-locking by a thread

Making pthread_rwlock_wrlock recursive

依然范特西╮ 提交于 2019-12-05 08:43:19
I have a problem regarding the behaviour of the pthread function pthread_rwlock_wrlock . The specification linked above states that when one thread has locked the lock for writing and the same thread locks it again, it results in undefined behaviour (I could actually observe this in that on x86 Linux calling this function is a noop and on PowerPC Linux it stalls the thread). The behaviour I need would be a read write lock that has the following characteristics: read-locking by a thread succeeds if: the lock is not held by any thread the lock is only read-locked by zero or more threads

Returning a RWLockReadGuard independently from a method

我是研究僧i 提交于 2019-12-01 22:42:37
I have an object of type Arc<RwLock<SessionData>> And I have a method that is supposed to take some kind of reference to SessionData fn some_method(session: ...) I'm using Rocket (a web-framework for Rust), and I can't directly invoke the method, because it is invoked by Rocket. However, I can provide it with an implementation that creates an object that will be passed to the handler. It looks a bit like this: impl<'a, 'r> request::FromRequest<'a, 'r> for SomeType { type Error = (); fn from_request(request: &'a request::Request<'r>) -> request::Outcome<Self, Self::Error> { // return object

Trying to return reference from RwLock, “borrowed value does not live long enough” Error

我是研究僧i 提交于 2019-12-01 07:13:29
问题 I've been working on my first Rust project recently but have hit a snag. I am using a HashMap mapping String s to AtomicUsize integers. The HashMap is protected by a RwLock to allow for concurrent access. I would like to be able to return references to AtomicUsize values in the HashMap , however if I try to return these references to the caller past the lifetime of the RwLockWriteGuard I get an error that borrowed value does not live long enough . I've reproduced a minimal example below and

Returning a RWLockReadGuard independently from a method

夙愿已清 提交于 2019-11-28 09:47:05
问题 I have an object of type Arc<RwLock<SessionData>> And I have a method that is supposed to take some kind of reference to SessionData fn some_method(session: ...) I'm using Rocket (a web-framework for Rust), and I can't directly invoke the method, because it is invoked by Rocket. However, I can provide it with an implementation that creates an object that will be passed to the handler. It looks a bit like this: impl<'a, 'r> request::FromRequest<'a, 'r> for SomeType { type Error = (); fn from