| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Resumes all threads blocked by a particular Mutex.
NotifyAll( <pMutexHandle> ) --> NIL
The function returns always NIL.
Function NotifyAll() sends a nodification to all threads having subscribed for a Mutex. As a result, all threads waiting for a notification on <pMutexHandle> resume program excution.
| See also: | GetCurrentThread(), GetThreadID(), HB_MutexCreate(), HB_MutexLock(), Notify(), StartThread(), Subscribe(), SubscribeNow() |
| Category: | Multi-threading functions , Mutex functions , xHarbour extensions |
| Source: | vm\thread.c |
| LIB: | xhbmt.lib |
| DLL: | xhbmtdll.dll |
// The example starts 5 threads which are suspended immediately after
// being started by Subscribe(). When the Main thread has created the
// threads, they are resumed after a key stroke. The Main thread then
// waits for the end of all threads before the program terminates.
PROCEDURE Main
LOCAL i, imax := 5
LOCAL pMutex := HB_MutexCreate()
CLS
FOR i:=1 TO imax
StartThread( "RunInThread", pMutex, 2*i )
ThreadSleep( 50 )
NEXT
WAIT "Press a key to notify all threads..."
NotifyAll( pMutex )
WaitForThreads()
RETURN
PROCEDURE RunInThread( pMutex, nRow )
LOCAL nCol
@ nRow, 0 SAY "Thread #" + LTrim( Str(GetThreadID()) )
nCol := Col()
Subscribe( pMutex )
DO WHILE nCol < MaxCol()
DispoutAt( nRow, ++nCol, "-" )
ThreadSleep(10)
ENDDO
RETURN
http://www.xHarbour.com