What\'s the best way to create a singleton in C? A concurrent solution would be nice.
I am aware that C isn\'t the first language you would use for a singleton.
Here's another perspective: every file in a C program is effectively a singleton class that is auto instantiated at runtime and cannot be subclassed.
extern in some header file).Give everything a proper prefix and now you can use my_singleton_method() in lieu of my_singleton.method().
If your singleton is complex you can write a generate_singleton() method to initialize it before use, but then you need to make sure all the other public methods check if it was called and error out if not.