As an IT staff, continuous learning and summarizing is our professional habit, so I will learn about each stage of learning through a bit of summary to record and test my own learning effect. Today we summarized the multi-threaded programming for Linux. technology:
1, thread creation, termination and control:
Any process has a main thread when it starts. If it needs to regenerate the thread, it uses the pthread_create function. In this function, you can specify the attributes of the thread, the thread routine, and the parameters passed to the thread routine. The thread routine is a user-defined function, and the code that the thread executes. When the thread routine returns, the thread finishes running, or you can display the call pthread_exit to exit. After the thread is created, you can use the pthread_self function to obtain the thread ID. The function pthread_join makes the process wait for the termination of the thread. After pthread_join is called, the process will be suspended until the specified thread (specified in pthread_join's thread parameter) terminates. The pthread_detach function is just the opposite, it allows the process does not have to wait for the end of the thread, allowing the process to continue to perform other operations, the detached thread after the execution of the resources it occupied by the system automatically recovered.
2, mutual exclusion between threads:
Mutual exclusion operation means that only one thread can execute this code when modifying a piece of code or a variable. Other threads cannot enter this code at the same time or modify variables at the same time. Pthreads often use the pthread_mutex mutex to implement thread exclusive operations. The pthread_mutex_init function is used to initialize a mutex variable. The pthread_mutex_lock function is used to lock the mutex variable. If the mutex has been locked by the thread when it is locked, the thread that calls the function will be blocked until the mutex is unlocked. The pthread_mutex_trylock tries to lock the mutex, but does not block when the mutex has been locked, but returns quickly. The pthread_mutex_unlock function unlocks the mutex. Pthread_mutex_destroy is used to release resources occupied by the mutex.
3, thread synchronization:
Synchronization means that several threads wait for the occurrence of an event. When the event occurs, execution continues together. Synchronize with condition variables in Linux threads. The function pthread_cond_init is used to create a condition variable. Pthread_cond_wait and pthread_cond_TImewait are used to wait for condition variables to be set. It should be noted that the two wait calls require a mutex mutex that has been locked. This is to prevent other threads from setting the condition variable before actually entering the wait state. And produce competition. Pthread_cond_broadcast is used to set a condition variable, even if an event occurs, and causes all threads waiting for the event to no longer block. The pthread_cond_signal is used to lift the blocking state of a waiting thread. Pthread_cond_destroy is used to release a resource for a condition variable.
4. Examples
Here we use the name producer/consumer problem as an example to illustrate the control and communication of Linux threads. A set of producer threads and a group of consumer threads contact through the buffer. The producer thread sends the produced product to the buffer, and the consumer thread removes the product from it. There are N buffers, which are a circular buffer pool.
E-cig as a substitute of tobacco mainly reminds people of its potential benefits for health. Four ingredients contain in the e-liquid : propylene glycol, glycerin vegetable, nicotine and food grade essence. Nevertheless, smoke from cigarette contains carbon monoxide, tar, arsenic, ammonia, and many other cyanide and acetone.
Advantage
- New ceramic self heating element, Uniform heating
- High reduction, Temperaturecan be accurately controlled
- Safety and Health, Worth a product,Natural and realistic taste,Factory Direct Sale
- Using proprietary technology,Quality assurance, trustworthy
- Oil leakage free, compact, pocket-sized, portable and easy to transport
-
So that smokers can smoke addiction, refreshing, to meet the psychological and physiological needs of smokers, and in line with the habit of smokers for many years.
-
Compared with rechargeable e-cigarettes and mechanical e-cigarettes, the price of disposable e-cigarettes is much lower, which is applicable to a wider range of customers than the first two. It is also the absolute truth for ordinary consumer groups to be cheap.
Wax Device Oem,Thc Wax Device Oem,Marijuana Wax Device Oem,High Cost Performance Wax Device
Shenzhen MASON VAP Technology Co., Ltd. , https://www.masonvap.com