Skip to main content

Multi-threading

1).What is multi-threading in C++?

1) Running multiple tasks concurrently
2) Running a single task concurrently
3) Executing multiple tasks sequentially
4) None of the above

2).Which header file is required for multi-threading in C++?

1) <thread>
2) <mutex>
3) <future>
4) All of the above

3).What is the default number of threads in a C++ program?

1) 1
2) 2
3) Depends on the hardware
4) None of the above

4).Which of the following is used to create a thread in C++?

1) std::thread
2) std::task
3) std::async
4) std::run

5).What is the role of the 'join()' function in multi-threading?

1) To pause the main thread until the thread completes
2) To detach a thread from the main thread
3) To cancel a thread
4) None of the above

6).What is a 'detached' thread in C++?

1) A thread that does not require joining
2) A thread that terminates after execution
3) A thread that runs in the background indefinitely
4) None of the above

7).What happens when you call 'join()' on a thread twice?

1) It throws an exception
2) It joins the thread multiple times
3) It causes undefined behavior
4) None of the above

8).What is a race condition in multi-threading?

1) A condition where multiple threads access shared data simultaneously
2) A condition where no threads run simultaneously
3) A condition where threads do not share data
4) None of the above

9).How can you avoid race conditions in C++?

1) By using mutexes
2) By using semaphores
3) By avoiding shared data
4) All of the above

10).What is the purpose of 'std::async' in multi-threading?

1) To run a function asynchronously
2) To create a new thread
3) To schedule a task for later execution
4) None of the above