THREADSAFE option descriptor 

Purpose

Specify that a procedure be made ThreadSafe accessing global data.

Syntax

SUB name() THREADSAFE

FASTPROC name() THREADSAFE AS Long

FUNCTION name() THREADSAFE AS Single

METHOD name() THREADSAFE

CLASS METHOD name() THREADSAFE

PROPERTY SET name(value) THREADSAFE

Remarks

When you create a program with multiple threads of execution, it is important to protect global data (global, threaded, static, and instance variables) from corruption by interaction of the threads. Generally speaking, that means a thread should be able to complete a sequence of operations on global data before another thread is allowed to begin that same sequence.

When a procedure is declared THREADSAFE, PowerBASIC automatically establishes a semaphore which allows only one thread to execute it at a time.  Others must wait until the first thread exits the THREADSAFE procedure before they are allowed to begin.

Obviously, THREADSAFE procedures should be made as small as possible. By limiting them to just the essential data access, you will minimize the possibility of unwanted delays of execution.

See also

FUNCTION, METHOD, PROPERTY, FASTPROC, SUB