Implementing Multiprocessing
147
To create a thread and bind it appropriately, use the following procedure:
1. Create a thread, as follows:
csThread* drawThread = new csThread(drawThreadEntry, NULL);
2. Bind the thread to a csWindow and csContext using csContext::makeCurrent(), as
follows:
static void
drawThreadEntry(void* arg)
{
csWindow *theWindow;
csContext *theContext;
theContext = theWindow->getThisWindowContext();
theContext->makeCurrent(theWindow);
// Context is now current; scenes will be drawn in theWindow.
...
}
Starting Threads
Whether or not a thread runs immediately depends on the csThread constructor you use.
The first form, csThread(), does not start executing. This behavior allows you to load
thread-related parameters before using csThread::start() to actually start the thread.
The second form of the constructor, csThread(Entry* entryPoint, void* arg=NULL),
allows you to load thread-related parameters in the argument. For that reason, it begins
execution immediately.