beautypg.com

Threading model – BrightSign BrightScript 2 Reference Guide User Manual

Page 21

background image

21

Threading Model

A BrightScript script runs in a single thread. The general rule of thumb is that Roku
Object calls are synchronous if they return quickly, or asynchronous if they take a long
time to complete. For example, class roArray methods are all synchronous. But if
“roVideoPlayer” is used to play a video, the play method returns immediately (it is
asynchronous). As the video plays, it will post events to a script created message port.
Typical events would be “media finished” or “frame x reached”.

Whether a Roku Object launches a background thread to perform asynchronous
operations is a decision made by the Object implementer. Often an object will have
synchronous and asynchronous versions of the same method.

This threading model means that the script writer does not have to deal with mutexes and
other synchronization objects. It is always single threaded and the message port is polled
or waited upon to receive events into the thread. However, Roku Object implementers
have to think about threading issues. For example, roList and roMessagePort are thread
safe internally so that they can be used by multiple threads.