CriticalSection

Included function to create and initialize a Critical Section Object.


OutputVar := CriticalSection()
Function Example: CriSec := CriticalSection()

Parameters

OutputVar

The name of the variable in which to store the pointer to the Critical Section Object.

General Remarks

A critical section object is useful in a multi-threaded environment (AutoHotkey.dll).
Critical Section Object provides synchronization similar to that provided by a mutex object but is used only by the threads of single process.
When Critical Section is owned by one thread and another thread tries to take ownership it will be halted and only continue once the thread released ownership.
To take ownership call EnterCriticalSection(CriSec), to release ownership call LeaveCriticalSection(CriSec). You can also call TryEnterCriticalSection(CriSec) if you don't want to lock current thread so it can still process messages, use Hotkeys, Timers...

Related

CriticalObject, AutoHotkey.dll

Examples

CriSec:=CriticalSection()
ahkdll:=AhkThread("CriSec:=" CriSec "`nLoop 5`nEnterCriticalSection(CriSec),MsgBox(`"Critical Section is now owned by AutoHotkey.dll`"),LeaveCriticalSection(CriSec),Sleep(10)")
Loop 5
	EnterCriticalSection(CriSec),MsgBox("Critical Section is now owned by AutoHotkey.exe"),LeaveCriticalSection(CriSec),Sleep(10)