AngelScript
Multi-thread support functions

Functions

AS_API int asPrepareMultithread (asIThreadManager *externalMgr=0)
 Sets up the internally shared resources for multithreading. More...
 
AS_API void asUnprepareMultithread ()
 Frees resources prepared for multithreading. More...
 
AS_API asIThreadManagerasGetThreadManager ()
 Get the thread manager used by the application. More...
 
AS_API void asAcquireExclusiveLock ()
 Acquire an exclusive lock. More...
 
AS_API void asReleaseExclusiveLock ()
 Release an exclusive lock. More...
 
AS_API void asAcquireSharedLock ()
 Acquire a shared lock. More...
 
AS_API void asReleaseSharedLock ()
 Release a shared lock. More...
 
AS_API int asAtomicInc (int &value)
 Increments the value by one and returns the result as a single atomic instruction. More...
 
AS_API int asAtomicDec (int &value)
 Decrements the value by one and returns the result as a single atomic instruction. More...
 
AS_API int asThreadCleanup ()
 Cleans up memory allocated for the current thread. More...
 
AS_API asILockableSharedBoolasCreateLockableSharedBool ()
 Create a lockable shared boolean. More...
 

Detailed Description

Function Documentation

◆ asAcquireExclusiveLock()

AS_API void asAcquireExclusiveLock ( )

This function will block the calling thread until there are no other threads that hold shared or exclusive locks.

◆ asAcquireSharedLock()

AS_API void asAcquireSharedLock ( )

This function will block the calling thread until there are no other threads that hold exclusive locks. Other threads may hold shared locks.

◆ asAtomicDec()

AS_API int asAtomicDec ( int &  value)
Parameters
[in]valueA reference to the value that should be decremented
Returns
The decremented value

This function is especially useful for implementing thread safe reference counters.

◆ asAtomicInc()

AS_API int asAtomicInc ( int &  value)
Parameters
[in]valueA reference to the value that should be incremented
Returns
The incremented value

This function is especially useful for implementing thread safe reference counters.

◆ asCreateLockableSharedBool()

AS_API asILockableSharedBool* asCreateLockableSharedBool ( )
Returns
A new lockable shared boolean.

The lockable shared boolean will be created with an initial reference count of 1, and the boolean value false.

The object can be used for weak reference flags.

◆ asGetThreadManager()

AS_API asIThreadManager* asGetThreadManager ( )
Returns
The thread manager prepared with asPrepareMultithread()

◆ asPrepareMultithread()

AS_API int asPrepareMultithread ( asIThreadManager externalMgr = 0)
Parameters
[in]externalMgrPre-existent thread manager (optional)
Returns
A negative value on error
Return values
asINVALID_ARGexternalMgr informed even though local manager already exists

Call this function from the main thread to set up shared resources for multithreading if engines are to be created in multiple threads.

If multiple modules (dlls) are used it may be necessary to call this with the thread manager retrieved from asGetThreadManager() in the main module in order for all modules to share the same thread manager.

See also
Multithreading

◆ asReleaseExclusiveLock()

AS_API void asReleaseExclusiveLock ( )

Releases the previously acquired exclusive lock.

◆ asReleaseSharedLock()

AS_API void asReleaseSharedLock ( )

Releases the previously acquired shared lock.

◆ asThreadCleanup()

AS_API int asThreadCleanup ( )
Returns
A negative value on error.
Return values
asCONTEXT_ACTIVEA context is still active.

Call this function before terminating a thread that has accessed the engine to clean up memory allocated for that thread.

It's not necessary to call this if only a single thread accesses the engine.

◆ asUnprepareMultithread()

AS_API void asUnprepareMultithread ( )

If asPrepareMultithread() has been called, then this function should be called after the last engine has been released to free the resources prepared for multithreading.