none
Race between WdfTimerStart and WdfTimerStop. RRS feed

  • Question

  • Hi, 

    My driver has a WDF timer object. The EvtTimerFunc of the timer object calls WdfTimerStart after it finishes processing whatever it needs to. 

    Now, i have another thread which calls WdfTimerStop with the wait parameter set to TRUE. 

    What happens in the following two scenarios ?

    Scenario 1:

    EvtTimerFunc: Gets swapped out. 

    Other Thread: Calls WdfTimerStop(timer, TRUE); goes into wait state ?

    EvtTimerFunc: wakes up, calls WdfTimerStart again. 

    In this case will the timer start up again ? Will WdfTimerStop returns as soon as the EvtTimerFunc returns despite having called WdfTimerStart ?

    Scenario 2: 

    EvtTimerFunc: does what it needs to, calls WdfTimerStart and has still not completed.

    Other Thread: Calls WdfTimerStop(timer, TRUE);

    EvtTimerFunc: Completes/Returns.

    Will WdfTimerStop return only after another EvtTimerFunc call back is executed ?

    I assume such use cases are common and the simplest solution would be to check on some sort of flag before restarting the timer in the EvtTimerFunc call back.

    Any help appreciated.

    Thanks.


    -R___K

    Thursday, April 30, 2015 2:31 PM

Answers

  • what all of this means is that you need to maintain state here. while the APIs cover many different call patterns, they can't cover all of them and you need to make sure you are calling them appropriately across diff threads.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, April 30, 2015 6:06 PM

All replies

  • 1) yes, it will start again if the Start() call comes after Stop(). in this case you should really create a periodic timer and eliminate the call to Start() from the timer callback

    2) yes, Stop() will wait until the callback returns.

    of course, you can now answer these questions on your own by looking at the WDF source on github


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Doron Holan [MSFT] Thursday, April 30, 2015 3:33 PM
    • Unmarked as answer by R___K Thursday, April 30, 2015 5:50 PM
    Thursday, April 30, 2015 3:33 PM
  • Thanks all. Forgot about github! 

    -R___K

    Thursday, April 30, 2015 4:35 PM
  • Guys,

    Thanks for the response. I looked at the code to confirm what you said but it looks like what you said might be incorrect. 

    If WdfTimerStart is called from the timer call back as indicated in my original question, it looks like WdfStopTimer will stop it again or WdfTimerStart will abort depending on the timing of the calls. 

    It looks like the framework will not allow the timer call back function to restart the timer if WdfStopTimer has been called with the wait flag set to TRUE.

    Itll be good if you guys can confirm this as well. 


    -R___K

    Thursday, April 30, 2015 5:54 PM
  • what all of this means is that you need to maintain state here. while the APIs cover many different call patterns, they can't cover all of them and you need to make sure you are calling them appropriately across diff threads.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, April 30, 2015 6:06 PM