(1) threads are also resources. Use pthread_join and pthread_detach to recycle memory.
(2) mutex will form a queue for the threads waiting for the lock, and the spinlock will constantly query the lock, similar to the processing of nonblock.
(3) After pthread_cond_wait, the lock will be released for another thread to operate. After the operation, pthread_cond_sign will be used to wake up. pthread_cond_wait must be used with mutex.
(4) Whether the read/write lock can be used as appropriate
(5) Try to use pthread_cond_waittime to replace pthread_cond_wait, and pthread_cond_wait has problems when processing the exit signal.
(6) the code in the lock should be as short as possible to prevent I/O and other time-consuming operations.
(7) try to use a ring message queue or buffer
(8) Try to make the operations of each thread not dependent on each other and form Pipeline operations. Each thread implements different tasks.
(9) Reduce the stack size and increase the number of threads
(10) pthread_join is used to process threads that are in the join state. resources must be recycled by the pthread_join call thread.
Pthread_detach is used to process threads in non-join conditions. Resources are automatically reclaimed after the thread ends.
(11) Pay attention to the differences between exit and pthread_exit, especially in the main thread. Exit indicates the exit of the entire process. The management thread notifies all threads of exit.
Pthread_exit is only the exit of a single thread, not a process
(12) pthread_mutex must be initialized with pthread_mutex_init, and destroy
(13) Pay attention to the implementation of linuxthread