Oregano
Oregano

Reputation: 57

Is there a way to discard an APC queue?

I use QueueUserAPC() function to add my asynchronuous procedure calls to the APC queue of my threads.

Let's say I have queued 10 calls to a thread, and while executing one of the calls after the thread entered SleepEx(), for some reason I decided not to execute next APCs. My primitive and simplistic solution to this problem is to wrap all the calls with an if block checking a global variable, and execute the block only if this condition variable is (or not) set.

Is there a better way to do this? Can I discard the APC queue of a thread so that the other calls queued in it will not be called?

Upvotes: 3

Views: 1037

Answers (1)

Eric Brown
Eric Brown

Reputation: 13932

There is no user-mode way to remove items from the APC queue. (You can from kernel mode, but even there, removing items from the APC queue is only done in teardown situations.) In any case, QueueUserAPC doesn't return a usable handle that you could cancel, and flushing the queue entirely is a bad idea because other code might have put items on the queue that you're not aware of.

Upvotes: 6

Related Questions