esp_pthread.rst 1.3 KB

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