My intent is to make it possible to rewrite function start assembly (.text) in a thread safe manner. The problem is that I cannot be sure other threads are not in the very beginning of the function while it is being rewritten. I write about 5 first bytes of the function. This operation is performed throughout all the process lifetime.
I have several ideas how to do this:
- Pausing other threads. Not bad. But it is ok on windows only. On linux there is no such a thing. You gotta implement it with signals, which complicates the operation and makes it hard to debug. Also it can harm the performance a lot, since it is a frequent operation.
- Using threads priority. The writing thread is granted higher priority, so others should wait for it. As I understand it it can only help on single-core platforms.
My question is are there another ways of doing so.