1
9
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ... */
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_pthread.h"7 includes
static void *example_thread(void * arg);
void app_main(void)
{
pthread_attr_t attr;
pthread_t thread1, thread2;
esp_pthread_cfg_t esp_pthread_cfg;
int res;
res = pthread_create(&thread1, NULL, example_thread, NULL);
assert(res == 0);
printf("Created thread 0x%"PRIx32"\n", thread1);
res = pthread_attr_init(&attr);
assert(res == 0);
pthread_attr_setstacksize(&attr, 16384);
res = pthread_create(&thread2, &attr, example_thread, NULL);
assert(res == 0);
printf("Created larger stack thread 0x%"PRIx32"\n", thread2);
res = pthread_join(thread1, NULL);
assert(res == 0);
res = pthread_join(thread2, NULL);
assert(res == 0);
printf("Threads have exited\n\n");
esp_pthread_cfg = esp_pthread_get_default_config();
esp_pthread_cfg.stack_size = 32768;
esp_pthread_cfg.prio += 2;
ESP_ERROR_CHECK( esp_pthread_set_cfg(&esp_pthread_cfg) );
res = pthread_create(&thread1, NULL, example_thread, NULL);
assert(res == 0);
printf("Created thread 0x%"PRIx32" with new default config\n", thread1);
res = pthread_join(thread1, NULL);
assert(res == 0);
printf("Thread has exited\n\n");
}{ ... }
static void *example_thread(void * arg)
{
usleep(250 * 1000);
printf("This thread has ID 0x%"PRIx32" and %u bytes free stack\n", pthread_self(), uxTaskGetStackHighWaterMark(NULL));
sleep(1);
printf("Thread 0x%"PRIx32" exiting\n", pthread_self());
return NULL;
}{ ... }