From the course: Parallel and Concurrent Programming with C++ Part 1

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Try lock

Try lock - C++ Tutorial

From the course: Parallel and Concurrent Programming with C++ Part 1

Start my 1-month free trial

Try lock

- When multiple threads each have multiple tasks to perform, making those threads block and wait every time they attempt to acquire a lock that's already taken may not be necessary or efficient. Olivia and I are two threads doing several different tasks. My thread will be taking an inventory of the fridge to see what things we're running low on, and then add those to the shopping list on our shared notepad. I'll go back and forth between those two tasks. - [Olivia] And my thread is searching through the newspaper for grocery coupons and then adding those items to the shared shopping list. Oh, there are some good deals this week. Now that I've found some items that I want, I'll take the pencil, which is our mutex to lock access to the shared notepad so I can add them. - I saw we're low on milk, so now I'll go to acquire the pencil and I see Olivia has it. If I attempt to lock a mutex in a regular blocking fashion, my…

Contents