ko1 / atdot.net wrote:
> ko1 (Koichi Sasada) wrote:
> > One off topic question. `list_empty()` is thread-safe?
> 
> Sorry it should be safe (I misread as other operation. sorry).

Right, good question, though...  for register_ubf_list
and unregister_ubf_list, they are safe and I can commit
below patch to clarify.

However, list_empty in ubf_threads_empty I'm not 100% sure
about...

```
diff --git a/thread_pthread.c b/thread_pthread.c
index 29805ef2df..febec0c1d1 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1125,6 +1125,15 @@ register_ubf_list(rb_thread_t *th)
 {
     struct list_node *node = &th->native_thread_data.ubf_list;
 
+    /*
+     * list_empty check is safe here without ubf_list_lock held
+     * because th->interrupt_lock is already held by
+     * rb_threadptr_interrupt_common.
+     *
+     *  rb_threadptr_interrupt_common
+     *    ubf_select (== th->unblock.func)
+     *      register_ubf_list (this function)
+     */
     if (list_empty((struct list_head*)node)) {
         rb_native_mutex_lock(&ubf_list_lock);
 	list_add(&ubf_list_head, node);
@@ -1141,6 +1150,11 @@ unregister_ubf_list(rb_thread_t *th)
     /* we can't allow re-entry into ubf_list_head */
     VM_ASSERT(th->unblock.func == 0);
 
+    /*
+     * list_empty check is safe here without ubf_list_lock held
+     * because we already cleared th->unblock.func while
+     * th->interrupt_lock was held.
+     */
     if (!list_empty((struct list_head*)node)) {
         rb_native_mutex_lock(&ubf_list_lock);
 	list_del_init(node);

```

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>