Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
How can a function figure out in which thread it's running?
So i was coding in my head last night when going to sleep and a question popped - how would my utility function figure out if it was called from the main thread or the render thread? I figured i'll ask the club here - it's probably something trivial, plus there might be multiple ways?
(If i need to elaborate "how come the developer does not know where he's calling the fn?" - assume the person writing the channel is different from the one that wrote some utility function, one can't rely they'll just call the fn from the "right" location and may want to build a check in)
Re: How can a function figure out in which thread it's running?
This is probably not anywhere near what you're looking for, but I had an idea - If your cycle has, say 9 steps, maybe keep a global variable that always updates which step it's on (1-9 or a-i), and in that function have it print which step that global variable is currently set to, thus giving a clue at least of what point in the cycle the function was called, such as an unexpected early point instead of the usual later on point.
Re: How can a function figure out in which thread it's running?
"Komag" wrote: This is probably not anywhere near what you're looking for
Correct. What i am asking for is how a standalone function - which cannot rely on additional parameters or global variables or on end-developer sense of decency - can determine through some voodoo inside its body if it's running in the render or main thread. You know, just like how through roAppInfo.isDev() it can determine if app is side-loaded or published. E.g. one heuristic i thought of was to check `m.top` - it exists in the render thread and does not^ exist in the main thread.
(^) that is, unless the Joker has assigned some value to m.top in main