esp_pthread.rst 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. .. highlight:: c
  13. ::
  14. main()
  15. {
  16. pthread_t t1;
  17. esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
  18. cfg.stack_size = (4 * 1024);
  19. esp_pthread_set_cfg(&cfg);
  20. pthread_create(&t1, NULL, thread_func);
  21. }
  22. The API can also be used for inheriting the settings across threads. For example:
  23. .. highlight:: c
  24. ::
  25. void * my_thread2(void * p)
  26. {
  27. /* This thread will inherit the stack size of 4K */
  28. printf("In my_thread2\n");
  29. }
  30. void * my_thread1(void * p)
  31. {
  32. printf("In my_thread1\n");
  33. pthread_t t2;
  34. pthread_create(&t2, NULL, my_thread2);
  35. }
  36. main()
  37. {
  38. pthread_t t1;
  39. esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
  40. cfg.stack_size = (4 * 1024);
  41. cfg.inherit_cfg = true;
  42. esp_pthread_set_cfg(&cfg);
  43. pthread_create(&t1, NULL, my_thread1);
  44. }
  45. API Reference
  46. -------------
  47. .. include:: /_build/inc/esp_pthread.inc