Lines Matching refs:thread
1 // This module provides a relatively simple thread-safe pool of reusable
4 // costly, in the case where a pool is accessed by the first thread that tried
25 // case of the first-to-get thread.
44 // does try to reuse space previously used by a thread that has since stopped,
64 /// An atomic counter used to allocate thread IDs.
68 /// A thread local used to assign an ID to a thread.
71 // SAFETY: We cannot permit the reuse of thread IDs since reusing a
72 // thread ID might result in more than one thread "owning" a pool,
75 // to be a sanity check. It is not expected that the thread ID space
81 panic!("regex: thread ID allocation space exhausted");
92 /// A simple thread safe pool for reusing values.
99 /// guaranteed to provide a value to exactly one thread at any time.
105 /// accessed by a thread that didn't create it.
110 /// The ID of the thread that owns this pool. The owner is the thread
116 /// It is initialized to a value of zero (an impossible thread ID) as a
119 /// A value to return when the caller is in the same thread that created
133 // being accessed in the same thread in which it was created. The 'stack' field
138 // thread. In our implementation below, we guarantee this by only returning the
139 // 'owner_val' when the ID of the current thread matches the ID of the thread
140 // that created the Pool. Since this can only ever be one thread, it follows
141 // that only one thread can access 'owner_val' at any point in time. Thus, it
144 // NOTE: It would also be possible to make the owning thread be the *first*
145 // thread that tries to get a value out of a Pool. However, the current
147 // thread (rather than the creating thread) is meaningfully better.
197 // Our fast path checks if the caller is the thread that "owns" this
198 // pool. Or stated differently, whether it is the first thread that
202 // SAFETY: We must guarantee that only one thread gets access to this
203 // value. Since a thread is uniquely identified by the THREAD_ID thread
204 // local, it follows that is the caller's thread ID is equal to the
205 // owner, then only one thread may receive this value.
225 // try to atomically set the owner. If we do, then this thread
294 // thread that first accesses the pool gets its own copy, while all other
306 let t1 = std::thread::spawn(move || {
313 let t2 = std::thread::spawn(move || {
325 // neither thread was first to access the pool, and because of the
326 // optimization, we should be guaranteed that neither thread mutates