Книга: Learning Concurrency in Python
Назад: Process execution sequence
Дальше: Critical sections

The solution

Now onto the important part--how do we solve the preceding problem so that we no longer live in fear of losing our bonuses in the future? In this relatively simple example, the answer would be to wrap the code that first reads the account balance, and execute any necessary transactions in a lock, which we'll go into more detail on later in this chapter.

By wrapping the code that performs the read of the account balance and the update in a lock, we ensure that Process A would first have to acquire the lock in order to both read and update our account balance, and likewise, for Process B. This would turn our non-deterministic program deterministic and free of our initial race condition. But by turning it into a deterministic program, we are, essentially, converting this section of code into a single-threaded, serial section of code that could impact performance if we were to have multiple threads.

Назад: Process execution sequence
Дальше: Critical sections

Download missing dll from Download unarc.dll page. Fix your error now!
Interested in hardrock? How about KISS? They are on a tour this year all across Canada and USA. Visit KISS Tour Dates Omaha to know more about KISS concert dates in 2019.
Carrie Underwood is my favourite country singer. She is young, beautiful and charming female in her 30s. Her strong voice takes me away from all troubles of this world so I start enjoy my life and listen songs created by her mind. Now the singer is on a Cry Pretty 360 Tour started in May of 2019. The concerts scheduled for this year, up to the 31st of October. Tickets are available for all men and women with different income. If you love country music as mush as I, then you must visit at least one of her concert. All tour dates are available at the Carrie Underwood tour Pittsburgh. Visit the website and make yourself familiar with all powerful Carrie Underwood concerts in 2019!