Class Thread.Thread
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Thread.Thread(func)
Exposes a threading API to JavaScript.
|
| Field Attributes | Field Name and Description |
|---|---|
| <inner> |
Uncaught exception which aborted the thread.
|
| <inner> |
State of the thread.
|
| <inner> |
Thread ID.
|
| <static> |
Thread.Thread.threadList
List of running threads.
|
| Method Attributes | Method Name and Description |
|---|---|
| <inner> |
exit(exitCode)
Terminate the current thread.
|
| <static> |
Thread.Thread.getcpuid()
Retrieve the ID of the CPU the current thread is running on.
|
| <inner> |
join()
Wait for a thread to join.
|
| <inner> |
run()
Function which is run when thread is spawned.
|
| <static> |
Thread.Thread.sleep(seconds)
Pause execution of the current thread.
|
| <inner> |
start()
Start the thread.
|
| <static> |
Thread.Thread.yield()
Yield execution of the current thread.
|
As of SpiderMonkey 1.8, there are multithreaded property access "gotchas" to be aware of. While previous releases to serialized access to objects, new optimizations in the engine have changed this - particularly for arrays. It is recommended that inter-thread communication be limited to manipulating properties of the the thread handle (which appears to the running thread as "this" in its outermost scope), and only checking those values when the thread joins. If only one value needs to be exchanged, the safest way is to use the Thread.exit() method.
The Thread class uses the GPSEE multiplexed branch callback to periodically yield and sweep for joined threads. This should insure good concurrency and reasonable resource consumption, even in applications which spawn many threads from JavaScript.
- Parameters:
- func
- Function to launch when thread is started.
- Throws:
- gpsee.module.ca.page.thread.constructor.notFunction when constructor is called without new
- gpsee.module.ca.page.thread.constructor.arguments.count when argument count is wrong
- gpsee.module.ca.page.thread.constructor.arguments.0.typeOf when first argument is not a function
- Returns:
- Thread handle in new state
- See:
- https://developer.mozilla.org/en/JS_THREADSAFE
- https://developer.mozilla.org/En/SpiderMonkey/Internals/Thread_Safety
The thread class uses the following GPSEE runtime configuration variables:
RC Variable Default Value Notes gpsee_thread_stack_chunk_size gpsee_stack_chunk_size RC variable or 8192 Stack chunk size for thread's context
- new
- runnable
- joining
- dead
Thread State Transition Diagram
void new runnable joining dead Why
============================================================================================================
|---Thread-----> Constructor
|--th_start--------> About to start NSPR thread
|-------------th_start----------------> NSPR thread failed to start
|--------thread_join---> Waiting on PR_JoinThread
|--thread_join-> Thread stopped running
|----------------------Thread_Finalize-------------------> Still born (never ran)
- Thread instance object is inserted into Thread.threadList when marked runnable
- Thread instance object is removed from Thread.threadList when marked dead
- Parameters:
- exitCode
- Value to pass back in thread handle, through its exitCode property. This method Treats exiting the primordial thread the same as calling gpsee.module.ca.page.ca.system.exit(). Note that exiting the main thread will not cause the program to terminate immediately, it will still block waiting for all the other threads to join and THEN exit.
- Returns:
- CPU ID
Blocks until either this thread (obj) has finished running, or it is discovered that this thread is not joinable (i.e. already joined, another thread trying to join, etc.)
All threads are created joinable, however it is not be possible to join a thread when:
- the thread was never started
- another thread is trying to join it
- the thread is no longer running
- Throws:
- gpsee.module.ca.page.thread.join.this when a thread tries to join itself.
- Returns:
- true when the thread was joined, false when it could not be joined
- Parameters:
- seconds
- Amount of time to sleep, accepts floats.