I need to exit FreeRTOS without aborting whole Windows application

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.

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

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

exit(0); aborts whole current process and it is not what I need.
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.

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 (30.1 KB)
FreeRTOSrunner.cpp (3.2 KB)
FreeRTOSrunner.h (1.6 KB)
portmacro.h (6.7 KB)

Thank you for taking time to share your solution.