nn::os::Thread Class

Header file: nn/os.h

Syntax

class Thread : public nn::os::WaitObject

Description

Class for representing threads.

Threads have priorities. The thread priority is specified as an integer from 0 to 31, with 0 indicating the highest priority. Standard threads specify the DEFAULT_THREAD_PRIORITY of 16.

A stack region is needed for thread operation. You can either directly specify a memory region for this stack region, or you can use AutoStackManager.

To directly specify a memory region, pass the stack region to the Start function when you start the thread. Pass a stack region that is an instance of a class that has a function similar to uptr GetStackBottom(). The StackMemoryBlock and StackBuffer classes meet these requirements, so they can pass the stack region directly.
Note: If you are directly specifying a memory region, be careful that the stack region does not get invalidated before the thread is destroyed. (For example, releasing it will invalidate it.)

To use AutoStackManager to manage the stack region, pass the stack size to the StartUsingAutoStack function when you start the thread.

Thread objects become valid once Start-series functions have been left. Note that it is not at the point when a thread starts running. The IsValid function can be used to check whether an object is valid.

You must always call Join explicitly before destroying Thread objects that were started using the Start function. You cannot call Detach.

You must always call either Join or Detach explicitly before destroying Thread objects that were started using the StartUsingAutoStack function.

Thread objects inherit WaitObject objects; when a thread is released from waiting, it means that the thread has exited. When it's necessary to perform non-blocking Join operations, call a function like WaitOne or WaitObject::WaitAny first to verify that the thread has been released from waiting.

You can create up to 32 Thread objects. Note also that different functions might use up resources that count against this limit.

Member Functions

Constructors/Destructors
Thread Constructor.
~Thread Destructor.
Starting Threads
Start Initializes and runs a thread.
TryStart Tries to initialize and run a thread.
StartUsingAutoStack Initializes and runs a thread.
TryStartUsingAutoStack Tries to initialize and run a thread.
Waiting for Termination and Releasing Resources
Finalize Destroys a thread object.
Join Waits for a thread to exit.
Detach Detaches thread so it is no longer subject to management.
IsAlive Gets whether the thread has completed.
Getters/Setters
GetId Gets the thread ID of an instance's thread.
GetPriority Gets the thread priority of an instance.
ChangePriority Sets the thread priority of an instance.
GetIdealProcessor Gets the preferred processor number of an instance.
S GetCurrentId Gets the thread ID of the current thread.
S GetCurrentPriority Gets the priority of the current thread.
S ChangeCurrentPriority Sets the priority of the current thread.
S GetCurrentProcessorNumber Gets the number of the processor that the current thread is running on.
Current Thread Control
S Sleep Puts the current thread to sleep for the time specified.
S Yield Gives threads with the same priority level as the current thread a chance to run.
Other
S GetMainThread Gets the object that represents the main thread.
S SetAutoStackManager Changes the AutoStackManager.
S GetCurrentCount Gets the number of Thread objects that are currently being used.
S GetMaxCount Gets the maximum number of Thread objects being used simultaneously.

Class Hierarchy

nn::util::NonCopyable
  nn::os::HandleObject
    nn::os::WaitObject
      nn::os::Thread

Revision History

2010/01/07
Initial version.

CONFIDENTIAL