Class Barrier[in Threading]

Gate controlling the transit of threads for certain operations.

class Barrier( [mode] ) \ from Waitable

more...

Summary

close()Closes the barrier.
open()Opens the barrier.

Inherited methods

release from Waitable Releases a structure acquired by a waiting function.

Detailed description

class Barrier( [mode] ) \ from Waitable

modeSet to true to initialize the barrier to open.

Gate controlling the transit of threads for certain operations.

The Barrier synchronization structure is a structure that can be either acquired by all or none of the threads willing to acquire it. If the barrier is open, then any wait on it will cause the calling thread to acquire it and proceed immediately, while if it's closed the waiting threads will be blocked forever, until the barrier gets open from the outside.

The methods open and close control the behavior of the barrier.

One use for the barriers is that of communicating a pool of threads a kind termination request; by sharing the barrier with all the threads in the pool, a controlling thread may control their behavior; if they wait on the barrier and on other resources, when the barrier is open they will acquire it, and in this way they will know that is time for a clean termination:

   class AThread( struct, bar ) from Thread
      bar = bar
      struct = struct
      ...
      function run()
         loop
            acquired = self.wait( self.bar, self.struct )
            if acquired == self.bar
               // end...
               return nil
            end

            //... work on self.struct
         end
      end
   end

Release is a no-op for a barrier.

Note: By default, the barrier is created in closed status. To create it in open status, pass the mode parameter as a true value.

Methods

close()

Closes the barrier.

Barrier.close( )

Prevents any thread to acquire the barrier. From this moment on, all the threads trying to wait on this barrier will block.

open()

Opens the barrier.

Barrier.open( )

Allow all the waiting threads to pass through the barrier.


Made with faldoc 2.2.1