One function is called from two diffirent files to load some data, in some cases it is loaded from one file and in some it is loaded from other. But in corner cases it is called from both the files, which should be avoid.
I can take a global variable or use a function to make sure loading of data happens only one time.
Looking for more elegant solution.
Is linux provide some API to achieve this?
Thanks
If you’re talking about multiple threads, then you need some kind of mutex around a static variable signifying whether the function has already run or not.
If you only have one thread, then you don’t need the mutex.