create_thread
Definition: | atom hThread = create_thread(integer rid, sequence params, integer flags=0) |
Description: |
Creates a new thread, using a call_proc based approach in a new and private call stack.
rid must be the routine_id of a procedure that can accept the parameters specified in params. The optional flags parameter can be CREATE_SUSPENDED to create a thread in a suspended state, which does not run until resume_thread(hThread) is called. For the default value of 0, execution begins immediately. |
pwa/p2js: | Not supported. |
Comments: |
Although not strictly necessary, the specified procedure should finish with a call to exit_thread().
Should a thread want to "return" a result, it should do so by sending an appropriate message, or perhaps setting a flag. Appropriate locking is required when operating on any data (including non-integer constants) that may be shared with any other threads. The main application should normally wait_thread(hThread) before terminating. |
Example: |
atom eThread = create_thread(routine_id("mythread"),{1}) ... terminate = 1 wait_thread(eThread) For a complete runnable example, see demo\rosetta\AtomicUrpdates.exw |
Implementation: | See builtins\VM\pThreadN.e (an autoinclude) for details of the actual implementation. |
See Also: | call_proc, routine_id, resume_thread, exit_thread, wait_thread |