If I have something like this...
volatile long something_global = 0;
long some_public_func()
{
return something_global++;
}
Would it b
On modern fast multicore processors, there is a significant overhead with atomic instructions due to caching and write buffers.
So compilers won't emit atomic instructions just because you added the volatile keyword. You need to resort to inline assembly or compiler-specific extensions (e.g. gcc atomic builtins).
I recommend using a library. The easy way is to just take a lock when you want to update the variable. Semaphores will probably be faster if they're appropriate to what you're doing. It seems GLib provides a reasonably efficient implementation.