Okay, another in-the-weeds question. Is there a way to come up with unique symbols for ticks within a thread? F’rinstance, is there a thread object that can be queried for, say, an id number?
I’m open to ideas on this one. I want to update some methods that spawn threads (lfo, env, trancegate, etc) so that if multiple instances are running simultaneously, the ticks aren’t stepping on each other.
Thanks!
I’m out and about at the moment, but yes, I have used this very technique myself. Will share some code when I hopefully have a chance some time later today ![]()
The method to use to get the current thread name is:
Thread.current.__system_thread_locals.get(:sonic_pi_local_spider_users_thread_name)
This applies to live_loops also.
The usual preamble about this being an internal/private method not part of the user API, and therefore subject to change without warning etc ![]()
Okay, that was an interesting rabbit hole. I started exploring the Thread class/object, which led me to the Object class/object. There’s an object_id value, which seems to be a unique number.
But maybe it would just be simpler to use another named tick that’s used only to generate unique id’s for the purpose of naming threads (or ticks) uniquely. It’s baroque, but it should work (and should always be supported):
define :uniquetickname do | prefix=""|
prefix + tick(:uniquetickkey).to_s #return val
end
Thanks for the leads. I’m always glad to learn new tricks, and you’re always insightful and helpful, @ethancrawford.
And it was interesting looking at all the info in the thread object, including __system_thread_locals.