C++ Multithreading Quiz

Last Updated :
Discuss
Comments

Question 1

Which of the following best describes multithreading?


  • A

    Running multiple processes on different machines

  • B

    Running multiple threads within the same process concurrently

  • C

    Running one thread after another in sequence

  • D

    Running multiple programs at the same time

Question 2

Which C++ header file is required to use std::thread?

  • A

  • B

  • C

     

  • D

Question 3

What will be the output of this code?

C++
#include 
#include 
using namespace std;
void task() {
cout << "Hello from thread";
}
int main() {
thread t(task);
t.join();
}


  • A

    No Output

  • B

    Compilation Error

  • C

    Hello from Thread

  • D

    Runtime Error

Question 4

Why is thread synchronization necessary?

  • A

    To make threads run faster

  • B

    To avoid thread creation overhead


  • C

    To prevent race conditions when accessing shared resources

  • D

    To make all threads execute in sequence


Question 5

Which of the following is used in C++ for thread synchronization?

  • A

    std::thread_guard

  • B

    std::condition_variable only

  • C

     std::sync

  • D

    std::mutex

Question 6

What happens if you call t.join() twice on the same std::thread object?

  • A

    The thread restarts


  • B

     It is ignored

  • C

    The program terminates without error

  • D

    The program throws std::system_error

Tags:

There are 6 questions to complete.

Take a part in the ongoing discussion