2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								ESP-pthread
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								===========
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Overview
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								--------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								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:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  *  Stack size of the pthreads
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  *  Priority of the created pthreads
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  *  Inheriting this configuration across threads
 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-28 20:40:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								  *  Thread name
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								  *  Core affinity / core pinning.
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Example to tune the stack size of the pthread:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								..  code-block ::  c
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    void * thread_func(void *  p)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    {
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf("In thread_func\n");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        return NULL;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    void app_main(void)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    {
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        pthread_t t1;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        cfg.stack_size = (4 * 1024);
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        esp_pthread_set_cfg(&cfg);
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        pthread_create(&t1, NULL, thread_func);
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								The API can also be used for inheriting the settings across threads. For example:
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								..  code-block ::  c
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								       
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    void * my_thread2(void *  p)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    {   
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        /* This thread will inherit the stack size of 4K * /
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf("In my_thread2\n");
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return NULL;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    void * my_thread1(void *  p)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    {
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        printf("In my_thread1\n");
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        pthread_t t2;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        pthread_create(&t2, NULL, my_thread2);
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        return NULL;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    }
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    void app_main(void)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    {
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        pthread_t t1;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-28 20:40:32 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        esp_pthread_cfg_t cfg = esp_create_default_pthread_config();
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								        cfg.stack_size = (4 * 1024);
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        cfg.inherit_cfg = true;
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        esp_pthread_set_cfg(&cfg);
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        pthread_create(&t1, NULL, my_thread1);
 
							 
						 
					
						
							
								
									
										
										
										
											2020-01-02 13:58:29 -03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    }
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								API Reference
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								-------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-11-13 11:46:16 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								..  include-build-file ::  inc/esp_pthread.inc
 
							 
						 
					
						
							
								
									
										
										
										
											2018-02-25 14:56:04 +05:30