Public Member Functions

Self_Lock Class Reference

An artificial thread deadlock at user disposal. Using Seal(int key_count) method caller causes calling thread to deadlock and wait until the deadlock situation is resolved by other process(es) calling Release() method key_count number of times. More...

#include <Semaphore.h>

Collaboration diagram for Self_Lock:
Collaboration graph
[legend]

List of all members.

Public Member Functions

unsigned int Prepare ()
 Should be called before using Seal() method. It ensures that Release() could not be called from other threads before Seal() method is executed.
unsigned int Seal (int key_count)
 Deadlocks calling thread. Other threads should then call Release() method key_count number of times to release the thread from deadlock.
unsigned int Release ()
 Represents using 1 key on the lock. After all key_count keys are used the thread that originally called Seal() method is released from deadlock state.

Detailed Description

An artificial thread deadlock at user disposal. Using Seal(int key_count) method caller causes calling thread to deadlock and wait until the deadlock situation is resolved by other process(es) calling Release() method key_count number of times.

The concept is best illustrated by a room which has a door with a special lock that requires multiple keys to be unlocked from outside and if the door is closed the lock automatically locks itself. Somebody knowing the construction of the special locking mechanism could enter the room, giving the number of keys required to open the door to his colleagues and close the door. This way a person stays locked in the room until all his colleagues return and use their keys to open the lock thus releasing him. Sounds like a weird game but that is what delivers high performance of parallel calculations of neurons with minimum synchronization overhead.

MCPN Logo
kr0st © 2010