From the course: Python Parallel and Concurrent Programming Part 1
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Read-write lock - Python Tutorial
From the course: Python Parallel and Concurrent Programming Part 1
Read-write lock
- We use a lock or mutex to protect a critical section of code to defend against data erases, which can occur when multiple threads are concurrently accessing the same location in memory and at least one of those threads is writing to that location. That second part is key, because if we have a bunch of threads and none of them are writing, they all just want to read from the same location, that's fine. It's okay to let multiple threads read the same shared value as long as no one else can change it. They'll all safely see the same thing. Danger only exists when you add a thread that's writing to the mix. When we use a basic lock or mutex to protect the shared resource, we limit access so that only one of the threads can use it at a time, regardless of whether that thread is reading or writing or both. - That works, but it's not necessarily the most efficient way to do things, especially when there are lots of threads…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.