| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== UNLOCKTHREAD (unlock the current execution thread) ====== | [[unlock unlock a locked data file .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[unquoteremovestring special characters .htm|{{btn_next_n.gif|Next page}}]] | | || **UNLOCKTHREAD** {{blk2blue.jpg|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 the event processor .htm|ACCEPT]] [[lockthread re lock the current execution thread .htm|LOCKTHREAD]] [[threadlocked returns current execution thread locked state .htm|THREADLOCKED]]