windows - c - interrupt a function call which is executing in a thread -


I have a DLL that has a thread function that looks like pseudocode:

  Unstable BOOL prevented = false; Zero StopEverything () {/ * Enter important section / prevented = TRUE; / * Skip important section * /} zero worker threadfun () {start (); / * Checkpoint 1 * / if (paused) {/ * Clean / return; } DoLaboriousTask1 (); / * Checkpoint 2 * / if (paused) {/ * Clean / return; } DoLaboriousTask2 (); Uninitialize (); }   

And in the code that uses this DLL, the cleaning function looks like this:

  zero cleanup () {StopEverything (); / * Wait for all threads to exit * / / * clean other * /}   

My question is two times:

  1. Is there a better How do I stop my workerThreadFunc () execution instead of checking on different checkpoints?
  2. Suppose workerThreadFunc () inside doLaboriousTask2) when the main application call StopEverything () . Interrupt doLaboriousTask2 () and how to get it out immediately?

    Thank you!

    Doing my workforce instead of checking on threadfunk () Is there a better way to stop?

    Probably no unmanaged code has no completely reliable way of stopping a thread in a pre-blank manner. Some prepares to do that which leads to and the document lists all kinds of serious consequences to use that function. For example:

    • If the target thread is the owner of an important segment, the important segment will not be released.
    • If target is allocating memory from thread map
    • If the target thread is executing some kernel 32 calls when it is terminated, then kernel 32 for the thread process The situation may be incompatible.
    • If the target thread is manipulating the global status of a shared DLL, the DLL's position may be lost, the DLL may affect other users.

      You ask:

      Is there any way to interrupt WBI's Task 2 () and get it out immediately?

      OK, you can call TerminateThread , but for all the reasons mentioned in the document, you should almost certainly not do this.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -