Skip to content

Commit

Permalink
Lang - perform thread move in no kill block
Browse files Browse the repository at this point in the history
This is coordinating change across two different thread's internal thread locals
  • Loading branch information
samaaron committed Jan 22, 2025
1 parent 2927df5 commit 886f868
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions app/server/ruby/lib/sonicpi/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1263,14 +1263,16 @@ def __named_thread(name)
end

def __move_thread_to_new_parent!(child_t, new_parent_t)
__remove_thread_from_parent_subthreads!(child_t)
__no_kill_block t do
__remove_thread_from_parent_subthreads!(child_t)

__system_thread_locals(new_parent_t).get(:sonic_pi_local_spider_subthread_mutex).synchronize do
new_parent_subthreads = __system_thread_locals(new_parent_t).get(:sonic_pi_local_spider_subthreads)
new_parent_subthreads.add(child_t)
end
__system_thread_locals(new_parent_t).get(:sonic_pi_local_spider_subthread_mutex).synchronize do
new_parent_subthreads = __system_thread_locals(new_parent_t).get(:sonic_pi_local_spider_subthreads)
new_parent_subthreads.add(child_t)
end

__system_thread_locals(child_t).set_local(:sonic_pi_local_parent_thread, new_parent_t)
__system_thread_locals(child_t).set_local(:sonic_pi_local_parent_thread, new_parent_t)
end
end

def __remove_thread_from_parent_subthreads!(t)
Expand Down

0 comments on commit 886f868

Please sign in to comment.