nsIThread
From MDC
This article covers features introduced in Firefox 3
The nsIThread interface provides high-level abstraction for operating system threads. Threads have a built-in event queue, and are event targets that can receive nsIRunnable objects (events) to be processed on the thread.
To create a thread, use the nsIThreadManager interface.
Inherits from: nsIEventTarget
Contents |
nsIThread is defined in source/xpcom/threads/nsIThread.idl. It is scriptable and
unfrozen (hasn't changed since Mozilla 1.9).
[edit] Method overview
void shutdown()
|
boolean hasPendingEvents()
|
boolean processNextEvent(in boolean mayWait)
|
[edit] Attributes
| Attribute | Type | Description |
PRThread
| PRThread
| The NSPR thread object corresponding to the nsIThread. Read only.
|
[edit] Methods
[edit] shutdown()
Shuts down the thread. This causes events to stop being dispatched to the thread, and causes any pending events to run to completion before the thread joins with the current thread (see PR_JoinThread() for details). During the execution of this method call, events for the current thread may continue to be processed.
void shutdown()
[edit] Parameters
None.
[edit] Exceptions thrown
- NS_ERROR_UNEXPECTED
shutdown()was erroneously called from within the thread itself, the thread was not created with the Thread Manager'snewThread()method, or the thread is already in the process of being shut down.
[edit] hasPendingEvents()
Determines whether or not the thread has events that are ready to be processed.
boolean hasPendingEvents()
[edit] Parameters
None.
[edit] Return value
true if there are pending events at the time the function was called. Since other threads may add events to the current thread, it's possible that by the time this method returns, the event queue may no longer be empty, even if a false result is reported.
[edit] Exceptions thrown
- NS_ERROR_UNEXPECTED
- The method was called when this thread wasn't the current thread.
[edit] processNextEvent()
Processes the next pending event. If there aren't any pending events, this method may wait -- depending on the value of the mayWait parameter -- until an event is dispatched to the thread.
This method is re-entrant but may only be called if this thread is the current thread.
boolean processNextEvent( in boolean mayWait )
[edit] Parameters
- mayWait
- If
true, this method blocks until an event is available to process if the event queue is empty. Iffalse, this method returns immediately if the queue is empty.
[edit] Return value
Returns true if an event was processed, or false if there were no pending events.
[edit] Exceptions thrown
- NS_ERROR_UNEXPECTED
- This method was called when this thread wasn't the current thread.