FlashKeepers

C and C++ · College · College and University

C++ VII: Concurrency and Memory Model

std::thread, mutex, lock_guard, condition_variable, atomics, memory orderings, futures and async.

About this set

36 basic cards for College C and C++. Set 7 of 7 in C++. It opens with "What does std::thread represent?" and "How do you create and start a std::thread?". Study it alongside the other College sets below.

36 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does std::thread represent?
Show answerA single thread of execution that can run concurrently with other threads.
How do you create and start a std::thread?
Show answerPass a callable (function, lambda, or functor) to the std::thread constructor; the thread starts immediately.
What does thread.join() do?
Show answerBlocks the calling thread until the target thread finishes execution.
What does thread.detach() do?
Show answerSeparates the thread object from the underlying thread, allowing it to continue running independently.
Can you copy a std::thread object?
Show answerNo, std::thread objects are not copyable; they have a deleted copy constructor and assignment operator.
What is a race condition?
Show answerWhen behavior depends on the relative timing of multiple threads accessing shared data without synchronization.
What is a mutex?
Show answerA mutual exclusion lock that ensures only one thread can access a protected resource at a time.
What does std::lock_guard do?
Show answerAutomatically acquires a mutex upon construction and releases it upon destruction following RAII.
How does std::unique_lock differ from std::lock_guard?
Show answerunique_lock allows manual lock and unlock, move semantics, and deferred locking, while lock_guard is simpler and always holds until destruction.
What is std::shared_lock used for?
Show answerIt allows multiple readers to hold the lock simultaneously while writers get exclusive access in read-write scenarios.
What is a std::condition_variable?
Show answerA synchronization primitive that allows threads to wait until a specific condition is signaled by another thread.
What does condition_variable::wait() do?
Show answerReleases the held mutex, blocks the thread, and reacquires the mutex upon being notified.
What is the difference between notify_one() and notify_all()?
Show answernotify_one() wakes one waiting thread, while notify_all() wakes all waiting threads.
What is std::atomic?
Show answerA template class providing atomic, indivisible access to a shared variable without explicit locks.
What are the main advantages of atomics over mutexes?
Show answerLower overhead, lock-free operation potential, no deadlock risk, and better performance for simple shared variables.

21 more cards in the app

Study this set free