README.md
1# C++ pthread Example
2
3(See the README.md file in the upper level 'examples' directory for more information about examples.)
4
5Support for the [C++ threads](http://www.cplusplus.com/reference/thread/thread/) in ESP-IDF is implemented on top of the [ESP-pthread](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/esp_pthread.html#overview) component. Thus, C++ threads created using the standard thread class constructor will automatically inherit the current ESP-pthread configuration. This example demonstrates how to leverage the thread configuration functions provided by ESP-pthread (e.g., `esp_pthread_get_default_config()` and `esp_pthread_set_cfg()`) to modify the stack sizes, priorities, names, and core affinities of the C++ threads.
6
7**Note: Due to the use of the C++ threads, this example is written in C++ instead of C.**
8
9## How to use example
10
11### Hardware Required
12
13This example should be able to run on any commonly available ESP32 development board.
14
15### Configure the project
16
17```
18idf.py menuconfig
19```
20
21* The default ESP-pthread configuration may also be modified under `Component config > PThreads`
22
23### Build and Flash
24
25Build the project and flash it to the board, then run monitor tool to view serial output:
26
27```
28idf.py -p PORT flash monitor
29```
30
31(Replace PORT with the name of the serial port to use.)
32
33(To exit the serial monitor, type ``Ctrl-]``.)
34
35See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
36
37## Example Output
38
39The following log output should appear when the example runs (note that the bootloader log has been omitted).
40
41```
42...
43I (380) Thread 1: Core id: 0, prio: 5, minimum free stack: 2068 bytes.
44I (0) pthread: This thread (with the default name) may run on any core.Core id: 1, prio: 5, minimum free stack: 2056 bytes.
45I (390) Thread 1: This is the INHERITING thread with the same parameters as our parent, including name. Core id: 0, prio: 5, minimum free stack: 2092 bytes.
46I (410) Thread 2: Core id: 1, prio: 5, minimum free stack: 2088 bytes.
47I (410) main: core id: 0, prio: 1, minimum free stack: 2928 bytes.
48```
49