I'm looking for a way to implement a functional equivalent of invokeOnMainThread(c# xamarin)/ runOnUiThread(android)/ performSelectorOnMainThread:(objective C) in C/C++ on linux.
Essentially what I need is a function, which can be called from any thread, to which I pass a handler, which is executed on the main thread.
I believe this will be helpful in cases where I want to restrict access to a particular resource to a particular thread (eg. libmysql DB access to main thread).
What would be an elegant way to implement this? How is it done in android?