# I need to exit FreeRTOS without aborting whole Windows application

**URL:** <https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059>\
**Category:** Kernel\
**Created:** [May 13, 2022, 5:20am UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059 "2022-05-13T05:20:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jara](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Jara](https://forums.freertos.org/u/Jara)\
**Post date:** [May 13, 2022, 5:20am UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/1 "2022-05-13T05:20:59Z")

</div>

I need to exit FreeRTOS without aborting whole Windows application. Why? FreeRTOS code is in DLL as a plugin to another application and DLL load could start FreeRTOS and DLL unload needs to correctly finish FreeRTOS.

I hope that I has been solved this task, and FreeRTOS can exit. In 99% FreeRTOS exits correctly. I would like to share my findings with others.

**I am rejected to upload my code as attachment, if you are interested in this patch, please allow me to upload code snippet.**

---

<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:** [May 13, 2022, 8:36pm UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/2 "2022-05-13T20:36:13Z")

</div>

The current code just calls exit( 0 ) - as per below. I updated your forum profile so hopefully you can upload a zip file now.

```auto
void vPortEndScheduler( void )
{
	exit( 0 );
}

```

---

<div class="post-metadata">

**Author:** ![Jara](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@Jara](https://forums.freertos.org/u/Jara)\
**Post date:** [May 13, 2022, 10:04pm UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/3 "2022-05-13T22:04:24Z")

</div>

exit(0); aborts whole current process and it is not what I need.  
[https://www.cplusplus.com/reference/cstdlib/exit/](https://www.cplusplus.com/reference/cstdlib/exit/)

Sometimes it is neccesary to use FreeRTOS in DLL plugin and not to destroy whole host application. Yes, there could be clear solution that DLL starts some isolated process, but the interprocess communication could be not too easy to design.

```auto
void vPortEndScheduler( void )
{
  SetEvent(pvInterruptEvent);
  ReleaseMutex( pvInterruptEventMutex );

  CloseHandle(pvInterruptEvent); // This will release all loops.
  CloseHandle(pvInterruptEventMutex);

  vTaskDelete(NULL); // The FreeRTOS calling thread must abort itself.
//exit( 0 );
}

```

My code is attached, it could be idea how to stop FreeRTOS this way. I know that it is a pretty hack, but it seems to work at least for my purpose. Prototype demonstrator on Windows does not need such critical stability like application in MCU. But still source code could be compilled to MCU without any change.

There could be another approach. When all threads commit suicide, main FreeRTOS thread exits.

[port.c](https://forums.freertos.org/uploads/short-url/taRivihdkFUWUFyHJAn2OB1lk71.c) (30.1 KB)  
[FreeRTOSrunner.cpp](https://forums.freertos.org/uploads/short-url/efhPcUhaY32R08EFO7Nx6Em8auO.cpp) (3.2 KB)  
[FreeRTOSrunner.h](https://forums.freertos.org/uploads/short-url/aPxi04ILC9zTD5RtFjfsO9Sa2ve.h) (1.6 KB)  
[portmacro.h](https://forums.freertos.org/uploads/short-url/a8EmYjsqDFmrL8dMQSVxkGHmtum.h) (6.7 KB)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [May 16, 2022, 10:12am UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/4 "2022-05-16T10:12:14Z")

</div>

Thank you for taking time to share your solution.

---

<div class="post-metadata">

**Author:** ![elamre](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/elamre/32/3802_2.png) [@elamre](https://forums.freertos.org/u/elamre)\
**Post date:** [September 4, 2023, 1:18pm UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/5 "2023-09-04T13:18:30Z")

</div>

Hello Jara,  
I’m running into the same issue as you did back then. And of course your solution works wonderful. However I’m trying to find a way not to change the FreeRTOS source. Have you since found another solution? The biggest issue I found is to close the pvInterruptEventMutex handle, since it’s static I have no way of accessing it from other sourcefiles.

@aggarg are there any plans to simplify this? or to include this in any way? I don’t understand why @Jara solution for example is not implemented in the windows port?

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [September 4, 2023, 4:24pm UTC](https://forums.freertos.org/t/i-need-to-exit-freertos-without-aborting-whole-windows-application/15059/6 "2023-09-04T16:24:27Z")

</div>

Have you tried the latest version because the implementation of the end scheduler has changed - [https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.6.1/portable/MSVC-MingW/port.c#L569](https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/V10.6.1/portable/MSVC-MingW/port.c#L569)
