Skip to content

Commit

Permalink
Merge pull request #53 from projectmemetic/master
Browse files Browse the repository at this point in the history
Sync optimization, fix potential multicore lock train
  • Loading branch information
cryptopepe authored Feb 27, 2019
2 parents 4f98c35 + dbab6bd commit 34acf39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,9 +1519,15 @@ void ThreadMessageHandler(int ncore)
if (pnode == pnodeSync)
fHaveSyncNode = true;
}

// check if one of the other threads has the sync node
BOOST_FOREACH(CNode* pnode, vNodesFullSet) {
if(pnode == pnodeSync)
fHaveSyncNode = true;
}
}

if (!fHaveSyncNode)
if (!fHaveSyncNode && IsSyncing()) // Only call this if IsSyncing is true
StartSync(vNodesCopy);

// Poll the connected nodes for messages
Expand Down
6 changes: 4 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,11 @@ class CNode
ssSend.GetAndClear(*it);
nSendSize += (*it).size();

// Don't attempt optimistic write here, because this may be called from one of the
// message handling threads. Leave it to be processed by the socket handling thread and avoid potential lock train.
// If write queue empty, attempt "optimistic write"
if (it == vSendMsg.begin())
SocketSendData(this);
//if (it == vSendMsg.begin())
// SocketSendData(this);

LEAVE_CRITICAL_SECTION(cs_vSend);
}
Expand Down

0 comments on commit 34acf39

Please sign in to comment.