Skip to content

Commit 2cb887a

Browse files
ethancrawfordsamaaron
authored andcommitted
Runtime - initialise rand distribution of new threads
Previously, the thread local tracking the current thread's random number distribution was only set to a specific value if the user explicitly called use_/with_random_source. (Otherwise, a white noise distribution was used _without setting the corresponding thread local_). With the introduction of a function to query the corrent random source, returning a source of nil is undesirable - so here, when creating a new thread, we query the thread local for the current random number distribution - _and explicitly set it to :white if it is nil_.
1 parent a315751 commit 2cb887a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app/server/ruby/lib/sonicpi/runtime.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,9 @@ def __in_thread(*opts, &block)
10491049
__thread_locals_reset!(new_tls)
10501050
__system_thread_locals_reset!(new_system_tls)
10511051
__set_default_system_thread_locals!
1052-
1052+
unless SonicPi::Core::SPRand.get_random_number_distribution
1053+
SonicPi::Core::SPRand.set_random_number_distribution!(:white)
1054+
end
10531055
__system_thread_locals.set_local(:sonic_pi_local_thread_group, :job_subthread)
10541056
__system_thread_locals.set_local(:sonic_pi_spider_thread_id_path, new_thread_id_path)
10551057
__system_thread_locals.set_local :sonic_pi_local_spider_users_thread_name, name if name

0 commit comments

Comments
 (0)