> Less memory - a pthread mutex is around 40 bytes, compared to 4 bytes for this queue.
This sort of thing is pretty ugly, and is one place where "portable" C and C++ really betrays the value of the language. Chances are many (often all) your uses are Linux, and so a futex is all you actually needed, which costs 4 bytes like this structure. But to be portable you can't ask for a futex, and it's deliberately not made easy to try to directly call into Linux system calls for futex since you'll probably get it wrong and then blame everybody else.
So you ask for pthread_mutex and now it's ten times bigger and you're regretting your life choices.
> So you ask for pthread_mutex and now it's ten times bigger and you're regretting your life choices.
It's 36 bytes bigger.
Unless you're for some reason doing embedded development with a resource constrained system running a UNIX-like OS, that is not a concern that registers anywhere.
And you get standard code that runs anywhere.
Arguing about 36 bytes per critical section makes no sense. You waste far more than that by handling a string.
This sort of thing is pretty ugly, and is one place where "portable" C and C++ really betrays the value of the language. Chances are many (often all) your uses are Linux, and so a futex is all you actually needed, which costs 4 bytes like this structure. But to be portable you can't ask for a futex, and it's deliberately not made easy to try to directly call into Linux system calls for futex since you'll probably get it wrong and then blame everybody else.
So you ask for pthread_mutex and now it's ten times bigger and you're regretting your life choices.