Browse Source

further synchronization

tristangurtler 3 years ago
parent
commit
7377b75536
2 changed files with 15 additions and 6 deletions
  1. 3 2
      prsona/src/clientMain.cpp
  2. 12 4
      prsona/src/orchestratorMain.cpp

+ 3 - 2
prsona/src/clientMain.cpp

@@ -122,6 +122,9 @@ int main(int argc, char *argv[])
      * CLIENT SETUP CODE
      */
 
+    struct synchronization_tool exitSync;
+    unique_lock<mutex> exitLock(exitSync.mtx);
+
     cout << "[" << seedStr << "] Establishing PRSONA client with the following parameters: " << endl;
     cout << "[" << seedStr << "] " << numServers << " PRSONA servers" << endl;
     cout << "[" << seedStr << "] " << numClients << " PRSONA clients" << endl;
@@ -143,8 +146,6 @@ int main(int argc, char *argv[])
     server.addWebSocketHandler("/ws", wsHandler);
 
     // Exit handler (allows client to be brought down by making correct GET request)
-    struct synchronization_tool exitSync;
-    unique_lock<mutex> exitLock(exitSync.mtx);
     exitSync.val = 0;
     exitSync.val2 = 0;
     RemoteControlHandler exitHandler(&exitSync, "Client coming down!");

+ 12 - 4
prsona/src/orchestratorMain.cpp

@@ -93,9 +93,9 @@ int main(int argc, char* argv[])
     
     cout << "[ORC] Starting BGN dealer server." << endl;
 
-    vector<thread> serverStartup, clientStartup;
+    vector<thread> serverStartup, clientStartup, clientReady;
     serverStartup.push_back(thread(start_remote_actor, targeter[dealerIP], true, "d", output, lambda, maliciousServers));
-    this_thread::sleep_for(ONE_SECOND);
+    this_thread::sleep_for(HALF_SECOND);
 
     cout << "[ORC] Starting other servers." << endl;
 
@@ -119,16 +119,24 @@ int main(int argc, char* argv[])
     for (size_t i = 0; i < numClients; i++)
     {
         clientStartup.push_back(thread(start_remote_actor, targeter[clientIPs[i]], false, "c" + to_string(i), output, lambda, maliciousServers));
-        this_thread::sleep_for(ONE_SECOND);
+        this_thread::sleep_for(HALF_SECOND);
     }
 
-    cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;    
+    cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;
 
     for (size_t i = 0; i < numClients; i++)
         clientStartup[i].join();
 
     wait_for_clients_created(dealerIP, dealerPort, numClients);
 
+    cout << "[ORC] Waiting for confirmation that clients are ready to continue." << endl;
+
+    for (size_t i = 0; i < numClients; i++)
+        clientReady.push_back(thread(wait_for_client_ready, clientIPs[i], clientPorts[i]));
+
+    for (size_t i = 0; i < numClients; i++)
+        clientReady[i].join();
+
     /*
      * MAIN ORCHESTRATOR LOOP CODE
      */