Reputation: 231203
Is there a variant of APCs, or some other technique in NT-based Windows OSes, that will force a specific thread to call a specific user function immediately (or, at least, interrupting user code), without waiting for the thread to enter an alertable wait?
I realize this can lead to all kinds of concurrency issues. The main goal I'd like to use it for is forcing a processor level memory barrier from another thread (and waiting for completion) - other methods to achieve this would be helpful, but I'm still curious if this is possible at all :)
Upvotes: 2
Views: 252
Reputation: 5635
You can do it, but it is not pretty. Since the thread is not expecting this, you will be very limited in what you can call. For example, you will not be able to call anything that uses any synchronization API.
If you still want to do it - SuspendThread
, GetThreadContext
, SetThreadContext
, and ResumeThread
will allow you to simulate a function call. You will have to preserve all registers, including the flags.
Obviously, this require platform-specific code. Also note that some user-mode code touches locations that are above the stack pointer so you may want to add some margin to the pushed return address.
Upvotes: 2
Reputation: 179907
No, because that in general violates assumptions held by the other thread. The other thread must assume it can be interrupted by the kernel, yes, but not user-mode code changing the process working set.
Upvotes: 1