User Tools

Site Tools


unlockthread_unlock_the_current_execution_thread_.htm
Navigation:  Language Reference > 13 - Built-in Functions >====== UNLOCKTHREAD (unlock the current execution thread) ====== Previous pageReturn to chapter overviewNext page

UNLOCKTHREAD

blk2blue.jpg

The UNLOCKTHREAD statement allows a Clarion program to call 3rd-party code or API procedures that contain their own message loop (like Clarion's ACCEPT loop).

Normally, ACCEPT loops in a Clarion program execute in turn (even in 32-bit programs) so that problems do not arise due to simultaneous access to data. Thread-switching only occurs at an ACCEPT statement, and thus only one thread can execute Clarion code at a time. However, if the currently executing thread calls an external procedure (including API functions) that (for example) opens a window and processes messages until the window closes, then other threads must be allowed to execute (co-operatively) to process their own messages. You do this by calling UNLOCKTHREAD before the external procedure, then LOCKTHREAD after it returns.

Because UNLOCKTHREAD may allow other threads to pre-empt the currently executing thread, it is important that you make NO calls to the Clarion runtime library between UNLOCKTHREAD and its corresponding LOCKTHREAD. This means you must not call any Clarion language procedure. You also must not perform any operations involving a STRING, CSTRING, PSTRING, DECIMAL, or PDECIMAL data types. The one exception is that you may pass a STRING, CSTRING, or PSTRING variable as a RAW parameter to an external (non-Clarion) procedure. Failure to observe this restriction may result in data on another thread becoming corrupted, or other generally unpredictable misbehavior.

The THREADLOCKED() procedure determines whether the thread has been unlocked or not.

Example:

UNLOCKTHREAD                   !Unlock the thread

MyLibraryCodeWithMessageLoop   !Call the code that has its own message loop

LOCKTHREAD                     !Re-lock the thread

See Also:

ACCEPT

LOCKTHREAD

THREADLOCKED

unlockthread_unlock_the_current_execution_thread_.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1