Core Function ThreadCreate

From Sputnik Wiki
Revision as of 19:53, 4 December 2011 by Alexpja (Talk | contribs)
Jump to: navigation, search
ThreadCreate( <name>, <function> )

Contents

Description

Create a new thread and start it off executing a function or some code

Sputnik supports multi-threading and you can create threads in your code to assist you.

Threads work best if you use them as *worker threads*.

Parameters

name

Name of a thread to create.

function

Either a function to call or a string to execute similar to Eval()

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

You can spawn as many threads as you wish however there are a few important things to consider with threads.

Example

ThreadCreate("th1", "Thread1Func();"); // This thread will execute a function
ThreadCreate("th2", "Thread2Func();"); // This thread will execute a function
ThreadCreate("th3", 'println("Thread 3 says hi");'); // This thread will execute code
 
inputc();
 
Function Thread1Func()
{
	while(true)
	{
		println("Hello from thread '" . ThreadName() . "'");
		sleep(500);
	}
}
 
Function Thread2Func()
{
	while(true)
	{
		println("Heya from thread '" . ThreadName() . "'");
		sleep(500);
	}
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox