Project

General

Profile

Misc #11904

Why was Thread.exclusive deprecated?

Added by bascule (Tony Arcieri) almost 5 years ago. Updated almost 2 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
[ruby-core:72543]

Description

See: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/52554

Why was Thread.exclusive deprecated? It is useful for when you're uncertain about whether the caller is multithreaded or not, and therefore cannot initialize a mutex because the mutex must be initialized in a thread-safe context where it's not possible for multiple caller threads to initialize the mutex concurrently.

One use case is here: this is an idempotent native function invoked via FFI. The contract is that it can be called repeatedly, but only by one thread at a time (concurrent calls from multiple threads can potentially corrupt its internal state):

https://github.com/cryptosphere/rbnacl/blob/master/lib/rbnacl.rb#L88

Thread.exclusive is useful because it provides an implicit mutex you can ensure is initialized correctly before any other threads start.

Also available in: Atom PDF