Referring to this post, my problem (summarized):

One main thread waits for connections, on accept() spawns a new thread for each connection. After we received n connections, the main thread dictates all threads what command to run, and must wait for all threads to finish, until issuing a new command later on.

I would love to know if this solves my problem efficiently and is correct.

static int mCommandToExecute = 0;
static int mNumberConnectedClients = 0;

void* handleRequest(void* arg) {

...

while (1) {
// Wait for a command here

printf("\nSending to client: %s\n", commands[mCommandToExecute]);
n = write(sockfd, commands[mCommandToExecute], length[mCommandToExecute]);
...

// Wait for all threads to finish here
}
}

void* startServer(void* arg) {

for (mNumberConnectedClients = 0; mNumberConnectedClients < maxConnections; ++mNumberConnectedClients) {
}

// Wait for all threads to have booted up and ready to execute a command
mCommandToExecute = 0;
for (int i = 0; i < 4; ++i) { // Run through 4 commands as an example
// At least one thread is still executing here
// All commands are done here
mCommandToExecute = i + 1; // No mutex is used here, so set variable before every threads reads it
}

// Wait for all threads to finish
for (int i = 0; i < maxConnections; ++i) {
}
}


The threading mechanics mostly look correct. Your main thread and your subthreads only share the mCommandToExecute and commands variables. The subthreads only read them between mWaitForCommand and mWaitForAllDone, and the main thread reads and writes the mCommandToExecute between mWaitForAllDone and waitForCommand. So no one is writing to this data while anyone else is reading it, and your data is thread-safe.
However your subthreads do not have any exit condition, so I expect the pthread_join will hang on the first one. When you reach that point, all your subthreads will be waiting for the next command. Joining the thread does not terminate it. It simply allows you to synchronize their termination. You need to add some signal for the subthreads to terminate, and then you need to invoke that signal and then pthread_barrier_wait(mWaitForCommand) to allow each subthread to proceed to check the termination signal.
One simple way to do this, if it's practical, would be to make the termination step the final "command". Rather than sending the termination command, the subthreads could recognize it and just return immediately. Your main thread would need to avoid waiting on mWaitForAllDone for that last command, though.