Libthreadar 1.6.0
Public Member Functions | List of all members
libthreadar::freezer Class Reference

Class freezer is a semaphore like construct that has no maximum value. More...

#include <freezer.hpp>

Public Member Functions

 freezer ()
 freezer constuctor
 
 freezer (const freezer &ref)=delete
 no copy constructor
 
 freezer (freezer &&ref)=default
 no move constructor
 
freezeroperator= (const freezer &ref)=delete
 no assignment operator (made private)
 
freezeroperator= (freezer &&ref) noexcept=default
 no move operator
 
 ~freezer ()
 Destructor.
 
bool waiting_thread () const
 Return whether the freezer has at least a pending thread waiting for another thread to unlock it.
 
void lock ()
 Request a "resource". More...
 
void unlock ()
 Release a "resource". More...
 
void reset ()
 Reset to initial state releasing any thread that could wait on the freezer.
 
int get_value () const
 Return the value of the freezer, that's to say the number of available "resources". More...
 

Detailed Description

Class freezer is a semaphore like construct that has no maximum value.

initialized with a value of zero, any call to lock() reduces the value by one, any call to unlock() increases it by one. A call to lock() when the current value is zero or less suspends the calling thread. A call to unlock() when at least one thread is suspended on the freezer awakes exactly one thread. A call to unlock() when the freezer value is zero or more does only increase the value, the calling thread is not blocked.

Definition at line 54 of file freezer.hpp.

Member Function Documentation

◆ get_value()

int libthreadar::freezer::get_value ( ) const
inline

Return the value of the freezer, that's to say the number of available "resources".

Note
a negative value gives the total number of threads that are suspended by calling lock() (well the opposit value of the number of threads more precisely).

Definition at line 99 of file freezer.hpp.

◆ lock()

void libthreadar::freezer::lock ( )

Request a "resource".

If the freezer value is zero or less, lock() reduces the freezer by one and suspends the calling thread. If the freezer value is strictly greater than zero, it only reduces the freezer value by one, the calling thread is not locked.

◆ unlock()

void libthreadar::freezer::unlock ( )

Release a "resource".

increase the freezer value by one. If at least one thread was suspended on the freezer, exactly one thread is awaken


The documentation for this class was generated from the following file: