-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Recently I'm reading the source code of fiber::mutex, I noticed thatfiber::mutex will yield in try_lock no matter whether holding the lock or not? What's the considerations behind it, and can we just return immediately after lock? Thanks in advance.
Lines 43 to 60 in 238487b
| bool | |
| mutex::try_lock() { | |
| context * active_ctx = context::active(); | |
| detail::spinlock_lock lk{ wait_queue_splk_ }; | |
| if ( BOOST_UNLIKELY( active_ctx == owner_) ) { | |
| throw lock_error{ | |
| std::make_error_code( std::errc::resource_deadlock_would_occur), | |
| "boost fiber: a deadlock is detected" }; | |
| } | |
| if ( nullptr == owner_) { | |
| owner_ = active_ctx; | |
| } | |
| lk.unlock(); | |
| // let other fiber release the lock | |
| active_ctx->yield(); | |
| return active_ctx == owner_; | |
| } |
Metadata
Metadata
Assignees
Labels
No labels