# Known issues with vTaskDelay() on Win32?

**URL:** <https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510>\
**Category:** Kernel\
**Created:** [November 9, 2018, 5:41pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510 "2018-11-09T17:41:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 9, 2018, 5:41pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/1 "2018-11-09T17:41:58Z")

</div>

**[alangillespie](https://sourceforge.net/u/alangillespie/)** wrote on [Friday, November 09, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#e9ca):

I wondered if there are any known issues with vTaskDelay() on Win32.

I’ve been trying to use the function in a simple system containing a single task that calls this function in an infinite loop, and it causes permanent suspension of the scheduler via uxSchedulerSuspended in tasks.c, which is set non-zero in vTaskSuspendAll() and never changed thereafter.

The task function is simply for (;😉 vTaskDelay(pdMS\_TO\_TICKS(1000));, which I had expected to wake up every second or so, but it never does.

I tried what is effectively the same thing using a repeating 1 second timer which notifies the task from its expiry callback, and everything works as expected.

Am I abusing vTaskDelay() here, or is there an issue?

Thanks,  
–Alan Gillespie

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 9, 2018, 7:13pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/2 "2018-11-09T19:13:55Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, November 09, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#e9ca/c20d):

The code you show should work fine. The Windows port is used  
extensively during develop and test. Although note on Windows you will  
not get accurate or consistent timing as it is not real-time.

Is there anything unusual about your system? Does your Windows machine  
have more than one core (the simulator in newer versions of FreeRTOS  
assume that to be the case). Have you modified the code in any way at  
all, even if you think it is in a way that doesn’t matter? Are you  
making any Windows system calls or trying to communicate with Windows  
threads that were not created with xTaskCreate() or xTaskCreateStatic()?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 12, 2018, 2:21pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/3 "2018-11-12T14:21:14Z")

</div>

**[alangillespie](https://sourceforge.net/u/alangillespie/)** wrote on [Monday, November 12, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#fbca):

Thanks for replying Richard. Like you, I’m hoping to use Windows as a development platform, so timing accuracy is not a problem. The version I mentioned above, using the repeating timer, is easily accurate enough for our purposes.

I am using FreeRTOS 10.1.1 straight out of the box, and built using Visual Studio 2017 with the latest update. It is not modified in any way, and the code is not doing anything apart from starting FreeRTOS with a single (trivial) task.

Is it worth me putting together a minimal solution and posting it here?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 14, 2018, 1:04pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/4 "2018-11-14T13:04:58Z")

</div>

**[alangillespie](https://sourceforge.net/u/alangillespie/)** wrote on [Wednesday, November 14, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#ab7c):

I can get the vTaskDelay() version to work by inserting printf() calls into some of the threads to adjust the timing. It can then run for varying lengths of time before eventually stopping.

It looks to me like there is a race condition there somewhere. I’ll keep looking into it and post what I manage to find, although it might take a while because I don’t get much time for this.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 14, 2018, 7:17pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/5 "2018-11-14T19:17:21Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 14, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#ab7c/c5f5):

printf() is a Windows system call, all of which have the potential to  
crash the execution because it can cause Windows to block a thread that  
the FreeRTOS kernel assumes it has complete control over. Are you  
making any other Windows system calls in your application?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 14, 2018, 7:23pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/6 "2018-11-14T19:23:14Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, November 14, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#ab7c/c5f5/48dd):

I just tried the following in the head revision from SVN (should be the  
same as the last release with respect to this test). I found ten  
seconds worth of ‘simulated’ time was about 15 seconds of real time -  
but that is expected and all else was fine:

```auto
volatile uint32_t ul = 0;

void vDummyTask( void *pvParameters )
{
     for( ;; )
     {
         vTaskDelay( 100 );
         ul++;
     }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 15, 2018, 4:34pm UTC](https://forums.freertos.org/t/known-issues-with-vtaskdelay-on-win32/7510/7 "2018-11-15T16:34:30Z")

</div>

**[alangillespie](https://sourceforge.net/u/alangillespie/)** wrote on [Thursday, November 15, 2018](https://sourceforge.net/p/freertos/discussion/382005/thread/1ab061c7bc/#ec8f):

I’m well aware of what printf() does. Perhaps I should make it clear that I get exactly the same result if I use an empty for loop {for (int i = 0; i \< xxxx; ++i) ;} to generate the delay. That means there are no Windows calls at all, other than those made by FreeRTOS itself.

My very first attempt, as I described in my first post, was exactly the same as your dummy task, but in my case vTaskDelay() never returns. Changing nothing, except inserting strategic delays, causes it to burst into life.

As I said above I haven’t had much time to look into this so I don’t yet know why. I’m not expecting you to fix something you can’t reproduce, but I would certainly appreciate any pointers you can give.
