Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

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)
0 Kudos
5 REPLIES 5
Komag
Roku Guru

Re: How can a function figure out in which thread it's running?

Can't pass an extra variable in scenegraph?
0 Kudos
EnTerr
Roku Guru

Re: How can a function figure out in which thread it's running?

"Komag" wrote:
Can't pass an extra variable in scenegraph?

read the 2nd paragraph i added. we were typing concurrently :mrgreen:
0 Kudos
Komag
Roku Guru

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.
0 Kudos
EnTerr
Roku Guru

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
0 Kudos
sgranger
Channel Surfer

Re: How can a function figure out in which thread it's running?

In case someone is still looking for this, there's the roSGNode.threadInfo() method that was introduced in OS 9.

Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.