Organizing semaphores into a pyramid
I wouldn't even use a switch here:

wait_sem(semaphore[me*2+1]);
wait_sem(semaphore[me*2+2]);
if (me==0) {
    signal_sem(semaphore[0]);    
}


Edit: I see the sequence is not quite linear. If you can come up with an easy mapping between me and the indices, this will work (but with a different formula). Otherwise, a switch statement may be the easiest way.

You can also bury the switch inside a map by mapping the input ints to the two indices (std::map&lt;int, std::pair&lt;int, int&gt; &gt;). It essentially does the same thing, but you can hide the ugly in a header file.