Compiler: clang++ x86-64 on linux.
It has been a while since I have written any intricate low level system code, and I ussualy program against the system primitives (windows and pthreads/posix). So, the in#s and out's have slipped from my memory. I am working with boost::asio
and boost::thread
at the moment.
In order to emulate synchronous RPC against an asynchronous function executor (boost::io_service
with multiple threads io::service::run
'ing where requests are io_serviced::post
'ed), I am using boost synchronization primitives. For curiosities sake I decided to sizeof
the primitives. This is what I get to see.
struct notification_object
{
bool ready;
boost::mutex m;
boost::condition_variable v;
};
...
std::cout << sizeof(bool) << std::endl;
std::cout << sizeof(boost::mutex) << std::endl;
std::cout << sizeof(boost::condition_variable) << std::endl;
std::cout << sizeof(notification_object) << std::endl;
...
Output:
1
40
88
136
Forty bytes for a mutex ?? ?? ? WTF ! 88 for a condition_variable !!! Please keep in mind that I'm repulsed by this bloated size because I am thinking of an application that could create hundreds of notification_object
's
This level of overhead for portability seems ridiculous, can someone justify this? As far as I can remember these primitives should be 4 or 8 bytes wide depending on the memory model of the CPU.