Skip to main content

Concurrency and Synchronization

1).What is concurrency in C++?

1) Executing multiple tasks in parallel
2) Executing multiple tasks without overlap
3) Executing tasks in a sequential order
4) None of the above

2).Which of the following is used for synchronizing threads in C++?

1) std::mutex
2) std::thread
3) std::async
4) std::condition_variable

3).What does 'std::mutex' do in C++?

1) It provides mutual exclusion to avoid race conditions
2) It allows for asynchronous execution
3) It blocks threads from execution
4) None of the above

4).Which function is used to lock a mutex in C++?

1) lock()
2) unlock()
3) try_lock()
4) None of the above

5).What is 'std::condition_variable' used for?

1) For synchronizing threads and notifying one thread to proceed
2) To pause a thread
3) For avoiding race conditions
4) None of the above

6).What happens if a thread tries to lock an already locked mutex?

1) The thread waits until the mutex is unlocked
2) The thread proceeds without waiting
3) The thread throws an exception
4) None of the above

7).What is a deadlock in multi-threading?

1) When threads are waiting for each other to release resources
2) When a thread is not executing
3) When threads execute in a single sequence
4) None of the above

8).Which of the following can prevent deadlocks in C++?

1) Using timeouts for locks
2) Avoiding circular wait
3) Using mutexes in the same order
4) All of the above

9).What is a semaphore used for?

1) To control access to shared resources
2) To monitor thread execution time
3) To synchronize thread priorities
4) None of the above

10).What is 'std::lock_guard' in C++?

1) A class that automatically locks and unlocks a mutex
2) A function that locks multiple mutexes
3) A method to lock a mutex manually
4) None of the above