FreeRTOS+POSIX Pre-configured Example
The pre-configured example documented on this page uses the FreeRTOS Windows port. It demonstrates how FreeRTOS+POSIX can be used to port a simple POSIX threading compliant application (in this case, an implementation of the actor model) to the FreeRTOS kernel. To demonstrate the concept, the application is built for execution on both Linux (which uses POSIX threads) and FreeRTOS.
On this page:
- The demo application
- Building and running the demo on Linux
- Building and running the demo using the FreeRTOS Windows port
This demo creates two types of actors: dispatcher and workers. Dispatchers tell workers what to do by sending different types of messages to the works. Each time a worker receives a message it performs a predefined routine that is dependent on the message it received. At the end of the demo the dispatcher notifies the workers that there is nothing more to do and all actors (dispatcher and worker) terminate.
Each actor is a thread that is created using the POSIX pthread_create() function. Messaging is performed through queues using the POSIX mq_open(), mq_send(), mq_timedsend() and mq_receive() functions.
- Download the posix_demo.c source file.
- Open a command line window and cd to the directory that contains the downloaded posix_demo.c source file.
- Compiler using the following command line:
gcc -Wall posix_demo.c -lpthread -lrt -o posix_demo
- Once built, execute the demo using the following command line.
- Download the free 2017 (minimum) Community edition of Visual Studio for C/C++.
- Download and unzip the pre-configured example for Visual Studio.
- From within the Visual Studio IDE, open the solution file FreeRTOS_Plus_POSIX_with_actor.sln, which is located in the \FreeRTOS-Plus\Demo\FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator folder of the unzipped files.
- From within the Visual Studio IDE, press F10 to build the project and start a debug session.
Note that FreeRTOS cannot return from main() without ending the entire application, so the native FreeRTOS API is used to create a task called vStartPOSIXDemo(), which then used to run the same actor demo as already demonstrated running on Linux.