esp_pthread.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ESP-pthread
  2. ===========
  3. Overview
  4. --------
  5. This module offers Espressif specific extensions to the pthread library that can be used to influence the behaviour of pthreads. Currently the following configuration can be tuned:
  6. * Stack size of the pthreads
  7. * Priority of the created pthreads
  8. * Inheriting this configuration across threads
  9. * Thread name
  10. * Core affinity / core pinning.
  11. Example to tune the stack size of the pthread:
  12. .. code-block:: c
  13. void * thread_func(void * p)
  14. {
  15. printf("In thread_func\n");
  16. return NULL;
  17. }
  18. void app_main(void)
  19. {
  20. pthread_t t1;
  21. esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
  22. cfg.stack_size = (4 * 1024);
  23. esp_pthread_set_cfg(&cfg);
  24. pthread_create(&t1, NULL, thread_func);
  25. }
  26. The API can also be used for inheriting the settings across threads. For example:
  27. .. code-block:: c
  28. void * my_thread2(void * p)
  29. {
  30. /* This thread will inherit the stack size of 4K */
  31. printf("In my_thread2\n");
  32. return NULL;
  33. }
  34. void * my_thread1(void * p)
  35. {
  36. printf("In my_thread1\n");
  37. pthread_t t2;
  38. pthread_create(&t2, NULL, my_thread2);
  39. return NULL;
  40. }
  41. void app_main(void)
  42. {
  43. pthread_t t1;
  44. esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
  45. cfg.stack_size = (4 * 1024);
  46. cfg.inherit_cfg = true;
  47. esp_pthread_set_cfg(&cfg);
  48. pthread_create(&t1, NULL, my_thread1);
  49. }
  50. API Reference
  51. -------------
  52. .. include-build-file:: inc/esp_pthread.inc