CondWait
 
Stops execution of current thread until some condition becomes true

Syntax

Declare Sub CondWait ( ByVal handle As Any Ptr, ByVal mutex As Any Ptr )

Usage

CondWait ( handle, mutex )

Parameters

handle
The handle of a conditional variable, or the null pointer (0) on failure.
mutex
The mutex associated with this conditional variable, which must be locked when testing the condition and calling CondWait

Description

Function that stops the thread where it is called until some other thread CondSignals or CondBroadcasts the handle.

Once the conditional variable is created with CondCreate and the threads are started, one of more of them can be set to CondWait for the conditional; they will be stopped until some other thread CondSignals that the waiting thread can restart. CondBroadcast can be used to restart all threads waiting for the conditional. At the end of the program CondDestroy must be used to avoid leaking resources in the OS.

When calling CondWait, mutex should already be locked. An atomic unlock of the mutex and wait on the conditional variable will occur. When the condition variable becomes signaled, mutex will be locked again and then execution will return to the thread after the CondWait call.

Example
Platform Differences

  • Condwait is not available with the DOS version / target of FreeBASIC, because multithreading is not supported by DOS kernel nor the used extender.
  • In Linux the threads are always started in the order they are created, this can't be assumed in Win32. It's an OS, not a FreeBASIC issue.

Dialect Differences

Differences from QB

  • New to FreeBASIC

See also