Thread Wrapper
- While developping Scilab 5.0 we had to manage threads both under Linux and Windows.
You will find a thread wrapper in SCI/modules/core/includes/Thread_Wrapper.h.
- This allow to manage basics operations among threads :
Thread variables management
__threadId
- An unique ID to identify the thread.
__threadLock
- A basic mutex.
See __Lock and __UnLock process below.
__threadSignal
- A basic signal that can send from one thread to another.
See __Wait and __Signal process below.
__InitLock
A __threadLock initialization function.
__InitSignal
A __threadSignal initialization function.
Lock and UnLock process
__Lock
This function locks a mutex (__threadLock)
- Once a mutex is locked, it must be unlocked before being locked again.
- If there are different threads that tries to lock the same mutex, they will be blocked until the mutex has been unlocked.
- Others threads will obtain the lock one after each unlock.
- There is no warranty as far scheduling is concerned.
- The first awaked thread will obtain the lock even if it has not been created first.
__UnLock
This function locks a mutex (__threadLock)
- If the mutex has not been locked before, it does nothing.
__Signal
This function raise a signal (__threadSignal)
- If there is a process waiting for this signal, it will make it continue.
- If there is no, it does nothing.
__Wait
This function make a process wait for a signal (__threadSignal) before continuing execution.
- If the signal is never raised the process will wait and be blocked endlessly.
__CreateThread(threadId, functionName)
This function create a new thread wich ID is stored in threadId (__threadId).
- The function functionName is executed in the new thread.
- The function profile must be :
void * functionName(void *in)
__WaitThreadDie
- This function make the current process wait until some thread as died.