# [Create RTOS Threads](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/threads/)

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/)
- [Create csolution project](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/create/)
- [Initialize the Operating System](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/initialize/)
- [Create RTOS Threads](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/threads/)
- [Build and run the application](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/build_and_run/)
- [Next Steps](https://learn.arm.com/learning-paths/embedded-and-microcontrollers/cmsis_rtx_vs/_next-steps/)

In this step, you’ll implement the main RTOS thread (`app_main`), which is primarily responsible for starting and managing the other threads in the system.

You’ll create three threads. The number and naming of the threads are flexible, so feel free to adjust as needed.

## Create the app_main() function

Click on the `+` icon within the `Source Files` Group, and add a new file `app_main.c`. Populate with the below.

```c
#include "cmsis_os2.h"

void thread1(void *);
void thread2(void *);
void thread3(void *);

void app_main(void *argument) {
	osThreadNew(thread1, NULL, NULL);	// Create thread1
	osThreadNew(thread2, NULL, NULL);	// Create thread2
	osThreadNew(thread3, NULL, NULL);	// Create thread3
}
```

## Create Threads

Now you can implement the functionality of the threads themselves. Start with a simple example. Each thread will say hello, and then pause for a period, forever.

Click on the `+` icon within the `Source Files` Group, and add a new file `threads.c`. Populate with the contents below.

```c
#include "cmsis_os2.h"
#include <stdio.h>

void __attribute__((noreturn)) thread1(void *argument) {
	for (;;) {
		printf("hello from thread 1\n");
		osDelay(1000);
	}
}

void __attribute__((noreturn)) thread2(void *argument) {
	for (;;) {
		printf("hello from thread 2\n");
		osDelay(1000);
	}
}

void __attribute__((noreturn)) thread3(void *argument) {
	for (;;) {
		printf("hello from thread 3\n");
		osDelay(1000);
	}
}
```
