13.07.2015 Views

TASKING Script Debugger User Guide

TASKING Script Debugger User Guide

TASKING Script Debugger User Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Debugger</strong> <strong>Script</strong> Language2.19. MultithreadingA script thread can start a new thread via the function $thread_start(function , argument array), asshown in the following example.func $ts($a, $b, $c){…}$thread_start($ts, [1, 2, 3]);An exception of type "#THREAD_NOT_STARTED" is thrown upon failure.Protecting data from simultaneous access by multiple threads can be done using a mutex. The followingtable lists the mutex support functions.Function$mutex_create()$mutex_destroy(mutexhandle)$mutex_lock(mutexhandle)$mutex_trylock(mutexhandle)$mutex_unlock(mutexhandle)DescriptionCreates a mutex.The return value is a mutexhandle,which is effectively a (unique) number.Deletes the specified mutex (*).Locks the specified mutex (*). If the mutex is alreadylocked, the calling thread is suspended until that isno longer the case. Note that a mutex is notrecursive, meaning that a thread will deadlock itselfby trying to lock a mutex it has locked already.As $mutex_lock(…) (*), but always returnsimmediately. The return value equals 1 if lockingsucceeded and 0 otherwise.Unlocks the specified mutex (*). If the mutex is notcurrently locked by the calling thread, an exceptionis thrown.(*) If the argument does not correspond to an existing mutex, an exception is thrown.41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!