本文整理汇总了C++中Process::SendCommitToAll方法的典型用法代码示例。如果您正苦于以下问题:C++ Process::SendCommitToAll方法的具体用法?C++ Process::SendCommitToAll怎么用?C++ Process::SendCommitToAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::SendCommitToAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewCoordinatorMode
void* NewCoordinatorMode(void * _p) {
//TODO: send tid to ConstructVoteReq;
Process *p = (Process *)_p;
ofstream outf("log/newcoord" + to_string(p->get_pid()) + "," + to_string(time(NULL) % 100), fstream::app);
outf << "New Coordinator = " << p->get_pid() << endl;
// connect to each participant
p->participant_state_map_.clear();
//set participant state map but only those processes that are alive
for (auto it = p->up_.begin(); it != p->up_.end(); it++) {
if (*it == p->get_pid()) continue;
if (p->ConnectToProcess(*it))
p->participant_state_map_.insert(make_pair(*it, UNINITIALIZED));
// else
// cout << "P" << p->get_pid() << ": Unable to connect to P" << *it << endl;
}
// return NULL;
string msg;
p->ConstructStateReq(msg);
p->SendStateReqToAll(msg);
outf << "sent state req" << endl;
p->WaitForStates();
ProcessState my_st = p->get_my_state();
// if(p->get_pid() == 1) return NULL;
bool aborted = false;
for (const auto& ps : p->participant_state_map_) {
if (ps.second == ABORTED)
{
aborted = true;
break;
}
}
if (my_st == ABORTED || aborted)
{
if (my_st != ABORTED)
{
p->LogAbort();
//only log if other process is abort.
//if i know aborted, means already in log abort
my_st = ABORTED;
}
for (const auto& ps : p->participant_state_map_) {
p->SendAbortToProcess(ps.first);
}
p->set_my_state(ABORTED);
p->RemoveThreadFromSet(pthread_self());
return NULL;
}
bool committed = false;
for (const auto& ps : p->participant_state_map_) {
if (ps.second == COMMITTED)
{
committed = true;
break;
}
}
if (my_st == COMMITTED || committed)
{
if (my_st != COMMITTED)
{
p->LogCommit();
my_st = COMMITTED;
}
p->SendCommitToAll();
p->set_my_state(COMMITTED);
p->RemoveThreadFromSet(pthread_self());
return NULL;
}
bool uncert = true;
for (const auto& ps : p->participant_state_map_) {
if (ps.second == PROCESSTIMEOUT)continue;
if (ps.second != UNCERTAIN)
{
uncert = false;
break;
}
}
if (uncert && my_st == UNCERTAIN)
{
outf << "sending abort" << endl;
p->LogAbort();
for (const auto& ps : p->participant_state_map_) {
p->SendAbortToProcess(ps.first);
}
p->set_my_state(ABORTED);
p->RemoveThreadFromSet(pthread_self());
return NULL;
}
//else
//.........这里部分代码省略.........