Zum Inhalt springen
L

Das Video kommt von YouTube: erst beim Abspielen verbindet sich die Seite mit YouTube (Google).

Mutex Lock

Udacity1:18 115.698 Aufrufe veröffentlicht Auf YouTube

Das Wichtigste aus dem Video

Tipp auf eine Zeit – das Video springt genau dorthin.

Transkriptautomatisch erstellt · 13 Zeilen
Herunterladen
  1. Now, in real life if I want to keep other people from taking my things or messing with things they shouldn't, I use
  2. a lock to stop them. In threaded programming, we use a similar concept to protect memory. Let's say that inside some procedure, there's
  3. a block where I manipulate some data, in our example, the variable a. And I need to be sure that no other thread
  4. touches this variable while I am working on it. Whether executing this procedure or another one. Well then, I can declare a lock
  5. variable, which should reside in shared memory, and put the lock on before I have it do my manipulation,
  6. and unlock it afterwards. And I should do the same wherever I manipulate this variable a. If some other
  7. thread running this code simply accesses the shared resource without using the lock, it won't be able to stop
  8. him. But if he does try to acquire the lock first, then this call to mutex lock will block until
  9. the lock variable shows that has been unlocked. And only then will this code proceed. And, of course, if
  10. the schedule had worked things out so that this call had been called first, then he would get the lock.
  11. And this call to acquire the mutex lock would block until this data manipulation was finished, and the mutex variable
  12. had been unlocked. And this way the threads are able to mutually exclude each other from using resources, hence these
  13. are called mutex locks.

Zum Nachlesen