Is there a way to throw an exception when a user tries to use a non thread-safe method of a class in a multithreaded context? I guess the issue is mostly to detect that multiple threads are trying to use the method. Or, is there a “not_synchronous” keyword/tag I could use on the function declaration?
Share
There is no easy way to do this, no. If you are detecting that multiple threads are using a method, then chances are you will have to be using thread-safe collections and the like. If you are doing all that then you might as well have to make the method itself thread-safe.