ByzantineGeneralThread Class Reference

Every instance of this class operates as a thread, in one of two operational modes: More...

#include <byzantinegeneralthread.h>

Collaboration diagram for ByzantineGeneralThread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ByzantineGeneralThread (const unsigned int kUniqueID, const char *kSharedMemName, const char *kMailboxVectorName, const bool kIsLoyal, const unsigned int kTotalNumberGenerals, const unsigned int kTotalNumberMessages, const unsigned int kBroadcastRoundsRequired, const char *kLogCategoryName, const bool kGenerateGraph, const char *kTraitorSetName)
 Create a thread that represents a single byzantine general, eiher in Commanding General mode or in Lieutenant Genearl mode.
 ~ByzantineGeneralThread (void)
 Destructor.
void Stop ()
 Request that this thread stop.
void Start ()
 Create and run this thread.

Private Types

typedef std::list< LocalOrderLocalOrderList
 List of orders that are generated within this instance.

Private Member Functions

void Run ()
 Begin executing this thread.
void BroadcastOrders ()
 Broadcast all queued orders from the previous round.
void LieutenantGeneralRun ()
 The Lieutenant General operational mode's run routine.
void CommandingGeneralRun ()
 The Commanding General operational mode's run routine.

Private Attributes

const unsigned int kUniqueID_
 This general's unique identifer (ID). The Commanding General is always 0, while the Lieutenant Generals are always > 0.
const bool kIsLoyal_
 TRUE if this General is loyal, FALSE otherwise. A loyal general will pass orders through unmolested, while a disloyal general will randomly corrupt orders passed through.
const unsigned int kTotalNumberGenerals_
 The total number of generals on the battlefield.
const unsigned int kTotalNumberMessages_
 The total number of messages this general is expected to receive during his lifetime.
const unsigned int kBroadcastRoundsRequired_
 The number of rounds to broadcast orders. Each round consists of receiving an order, appending my unique id, and queueing that order for transmission to the other generals during the next round.
const bool kGenerateGraph_
 TRUE to generate a DOT graph of the received messages, FALSE otherwise.
boost::shared_ptr< boost::thread > thread_
 This instance's thread information.
boost::interprocess::managed_shared_memory * segment_
 Shared memory segment reference. We communicate to the other generals via this shared memory region.
OrderTreereceived_orders_
 The Tree of received orders. Each received order's communication path is used to determine its placement in the tree. The Commanding Generals' initial order is always the root node. The set of all nodes at a given depth (level) represent all of the messages received in that round of communication.
SharedMemoryMailboxVectormailbox_vector_
 Shared memory region's vector of mailboxes. Each mailbox belongs to a single General where the index into the vector is the owning General's Unique ID (kUniqueID_). Other generals can queue messages for the owning general by placing Orders for that general into his mailbox. The owning general will read orders out of his mailbox during rounds.
LocalOrderList order_transmit_queue_
 The list of orders we want to transmit at the beginning of the next round.
log4cpp::Category & log_
 Debug logger reference.
unsigned int rand_seed_
 Seed used in random number generator.

Detailed Description

Every instance of this class operates as a thread, in one of two operational modes:

1. Commanding General - Kick off initial order to Lieutenant Generals, and control when each of the Lieutenant Generals are allowed to begin their rounds of communication.

2. Lieutenant General - Wait for orders from other generals, generate orders to other generals, and coordinate with the Commanding General for when messages may be sent or received (rounds). Upon reception of a message (aka Order), this general will append his unique ID to the received message and queue broadcasting that message to all other generals. Prior to beginning each round, and upon completion of each round, this thread will coordinate with the Commanding General thread to begin subsequent rounds.

Definition at line 44 of file byzantinegeneralthread.h.


Member Typedef Documentation

typedef std::list<LocalOrder> ByzantineGeneralThread::LocalOrderList [private]

List of orders that are generated within this instance.

Definition at line 111 of file byzantinegeneralthread.h.


Constructor & Destructor Documentation

ByzantineGeneralThread::ByzantineGeneralThread ( const unsigned int  kUniqueID,
const char *  kSharedMemName,
const char *  kMailboxVectorName,
const bool  kIsLoyal,
const unsigned int  kTotalNumberGenerals,
const unsigned int  kTotalNumberMessages,
const unsigned int  kBroadcastRoundsRequired,
const char *  kLogCategoryName,
const bool  kGenerateGraph,
const char *  kTraitorSetName 
)

Create a thread that represents a single byzantine general, eiher in Commanding General mode or in Lieutenant Genearl mode.

Parameters:
kUniqueID Unique Identifier for this thread. When 0, this thread will be the commanding general. When > 0, this thread will be a Lieutenant General.
kSharedMemName The shared memory area's name.
kMailboxVectorName The name of the mailbox vector within the shared memory area.
kIsLoyal TRUE if this general is set to loyal, FALSE if disloyal
kTotalNumberGenerals The total number of generals involved in this problem
kTotalNumberMessages The total number of messages this general should expect to receive during his lifetime.
kBroadcastRoundsRequired The number of rounds this general should broadcast for.
kLogCategoryName The name of the logging category to use for output.
kGenerateGraph TRUE if this general should generate a DOT output graph from the tree of received messages, FALSE otherwise.
kTraitorSetName The set in which the unique identifiers of all of the traitors are stored.

Definition at line 26 of file byzantinegeneralthread.cpp.

ByzantineGeneralThread::~ByzantineGeneralThread ( void   ) 

Destructor.

Definition at line 62 of file byzantinegeneralthread.cpp.


Member Function Documentation

void ByzantineGeneralThread::BroadcastOrders (  )  [private]

Broadcast all queued orders from the previous round.

Definition at line 104 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ByzantineGeneralThread::CommandingGeneralRun (  )  [private]

The Commanding General operational mode's run routine.

Definition at line 142 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ByzantineGeneralThread::LieutenantGeneralRun (  )  [private]

The Lieutenant General operational mode's run routine.

Definition at line 216 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ByzantineGeneralThread::Run (  )  [private]

Begin executing this thread.

Definition at line 310 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ByzantineGeneralThread::Start (  ) 

Create and run this thread.

Definition at line 70 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:

void ByzantineGeneralThread::Stop (  ) 

Request that this thread stop.

Definition at line 82 of file byzantinegeneralthread.cpp.

Here is the call graph for this function:


Member Data Documentation

The number of rounds to broadcast orders. Each round consists of receiving an order, appending my unique id, and queueing that order for transmission to the other generals during the next round.

Definition at line 143 of file byzantinegeneralthread.h.

TRUE to generate a DOT graph of the received messages, FALSE otherwise.

Definition at line 149 of file byzantinegeneralthread.h.

const bool ByzantineGeneralThread::kIsLoyal_ [private]

TRUE if this General is loyal, FALSE otherwise. A loyal general will pass orders through unmolested, while a disloyal general will randomly corrupt orders passed through.

Definition at line 124 of file byzantinegeneralthread.h.

const unsigned int ByzantineGeneralThread::kTotalNumberGenerals_ [private]

The total number of generals on the battlefield.

Definition at line 129 of file byzantinegeneralthread.h.

const unsigned int ByzantineGeneralThread::kTotalNumberMessages_ [private]

The total number of messages this general is expected to receive during his lifetime.

Definition at line 135 of file byzantinegeneralthread.h.

const unsigned int ByzantineGeneralThread::kUniqueID_ [private]

This general's unique identifer (ID). The Commanding General is always 0, while the Lieutenant Generals are always > 0.

Definition at line 117 of file byzantinegeneralthread.h.

log4cpp::Category& ByzantineGeneralThread::log_ [private]

Debug logger reference.

Definition at line 210 of file byzantinegeneralthread.h.

Shared memory region's vector of mailboxes. Each mailbox belongs to a single General where the index into the vector is the owning General's Unique ID (kUniqueID_). Other generals can queue messages for the owning general by placing Orders for that general into his mailbox. The owning general will read orders out of his mailbox during rounds.

Definition at line 199 of file byzantinegeneralthread.h.

The list of orders we want to transmit at the beginning of the next round.

Definition at line 205 of file byzantinegeneralthread.h.

unsigned int ByzantineGeneralThread::rand_seed_ [private]

Seed used in random number generator.

Definition at line 215 of file byzantinegeneralthread.h.

The Tree of received orders. Each received order's communication path is used to determine its placement in the tree. The Commanding Generals' initial order is always the root node. The set of all nodes at a given depth (level) represent all of the messages received in that round of communication.

Definition at line 189 of file byzantinegeneralthread.h.

boost::interprocess::managed_shared_memory* ByzantineGeneralThread::segment_ [private]

Shared memory segment reference. We communicate to the other generals via this shared memory region.

Definition at line 180 of file byzantinegeneralthread.h.

boost::shared_ptr<boost::thread> ByzantineGeneralThread::thread_ [private]

This instance's thread information.

Definition at line 174 of file byzantinegeneralthread.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Generated on Mon May 31 15:35:43 2010 for Byzantine Generals Coding Sample by  doxygen 1.6.3