CPU thread starvation and hunger

Thread starvation:

The process can not get resources, (cpu io resources or resources or whatever), so it can not go on

For example, readers write the problem, if the reader first, then write could starve to death.

Another example is an exercise operating system concepts.

With broadcast may be able to solve a problem. Because the signal can wake up the thread according to the order into the team, while at the same time broad wake.

Note 7.15 with the condition variable is not the semaphore.

Here we engage in a prev prevent hunger.

Meanwhile here's wait and P operating on somewhat different.

Another idea is to do two variables turn and wantin, like Dekker and Peterson's algorithm. In fact, about the same effect. But there is no use semaphores.


 

 


 

cpu hunger:

After the program parallelization, you will encounter problems accessing shared data. If multiple threads to shared data is read-only operations, it does not require access to shared data lock protection. If multiple threads access of shared data write operation, the access to shared data must lock protection.

Shared data access model has a lock-protected, once made a thread lock, other threads must wait for a lock during operation. So that only one thread is running, resulting in only a CPU core running other CPU cores are hungry.

Guess you like

Origin www.cnblogs.com/lqerio/p/11117628.html