xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

NotifyAll()

Resumes all threads blocked by a particular Mutex.

Syntax

NotifyAll( <pMutexHandle> ) --> NIL

Arguments

<pMutexHandle>
This is the handle of the Mutex to notify. It is the return value of HB_MutexCreate().

Return

The function returns always NIL.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe