Using mutex to share data between two threads

Running two or more threads independently, where each accesses its own resources, is quite convenient. However, sometimes, we want the threads to share and process the same resource simultaneously so that we can finish a task faster. Sharing a common resource may lead to problems, as one thread might read the data before the other thread writes the updated data, leading to an ambiguous situation. To avoid such a situation, mutex is used. In this recipe, you will learn how to share common resources between two threads.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset