Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Threads

Threads provide a way for a program to split itself into two or more simultaneously running tasks. A program can use "threads of execution" to simultaneously perform different functions within that program, which can improve efficiency. For example, one thread may be waiting for a timer or external event, while another thread is performing a calculation.

Each process can instantiate one or more threads. An object can only be called by a thread within the same process. If there are multiple threads serving invocation requests, processes accept requests from a common queue.

Thread-safety

Multiple threads that access common data must be synchronized to achieve thread-safe execution. Critical sections or atomic operations provide the needed synchronization when common data is accessed by multiple threads.

Objects exported from the kernel process (a privileged domain) or from multithreaded user processes (a less privileged domain) must be thread-safe.

Priority

Each thread has a predefined priority. When multiple threads are waiting, the one with highest priority gets access when available. Thread priorities are not escalated to the caller priority. Invocation is non-reentrant: a thread waiting to complete an invocation is unavailable to serve other incoming requests.

The kernel hosts a designated server thread for each of the user threads in user processes. This ensures that invocations of common services (such as the file system or device drivers) can proceed without priority inversion. Priority-sensitive tasks can be moved to an isolated domain without introducing the possibility of priority inversion.

Thread cleanup

Killing a process kills its threads. If a thread is interrupted while serving an invocation from another process, the caller will see the invocation immediately complete with an appropriate error code indicating that the server has terminated. Likewise, if a thread is interrupted after invoking another process and waiting on the result, the invoking thread is immediately discarded. The invoked object will continue to execute uninterrupted, but the return value will be discarded.