MCQs on Concurrency and Parallelism | Haskell

Haskell is a powerful functional programming language that supports concurrency and parallelism, enabling efficient execution of multiple tasks simultaneously. Concurrency allows multiple tasks to progress without necessarily executing simultaneously, while parallelism takes advantage of multiple processors or cores to perform tasks at the same time. Haskell provides various abstractions like forkIO, MVar, Chan, and STM (Software Transactional Memory) for managing concurrency and parallel computation, making it a popular choice for high-performance applications.

Topics Overview:

  • Introduction to concurrency in Haskell
  • Using forkIO, MVar, and Chan for concurrency
  • STM (Software Transactional Memory)
  • Basic parallel computation and lazy parallelism

MCQs on Concurrency and Parallelism in Haskell

1. Introduction to Concurrency in Haskell

  1. What is the primary concept of concurrency in Haskell?
    • A) Executing tasks on separate threads
    • B) Managing multiple tasks simultaneously without direct synchronization
    • C) Running tasks sequentially
    • D) Distributing tasks across multiple machines
  2. Which of the following describes Haskell’s approach to concurrency?
    • A) Cooperative multitasking
    • B) Preemptive multitasking
    • C) Explicit multithreading only
    • D) No concurrency support
  3. Which abstraction does Haskell provide to manage concurrency?
    • A) Threads
    • B) Channels
    • C) Forking
    • D) MVar
  4. What is the main benefit of concurrency in Haskell?
    • A) Parallel execution of code on multiple processors
    • B) Efficient management of multiple independent tasks
    • C) Automatic memory management
    • D) Reducing CPU usage
  5. In Haskell, concurrency is achieved by:
    • A) Using non-blocking IO
    • B) Using forkIO to create new threads
    • C) Automatically splitting tasks across processors
    • D) Using lazy evaluation

2. Using forkIO, MVar, and Chan for Concurrency

  1. What does the forkIO function in Haskell do?
    • A) It creates a new thread that runs concurrently
    • B) It handles software transactional memory
    • C) It synchronizes multiple threads
    • D) It performs parallel computation
  2. Which data structure is used in Haskell to safely share state between threads?
    • A) IORef
    • B) MVar
    • C) Chan
    • D) List
  3. The MVar in Haskell is used for:
    • A) Storing values in a thread-safe way
    • B) Passing messages between threads
    • C) Defining parallel tasks
    • D) Synchronizing IO operations
  4. What is the primary use of Chan in Haskell?
    • A) Managing IO operations
    • B) Passing messages between threads
    • C) Defining parallel computation
    • D) Ensuring lazy evaluation
  5. Which of the following is true about MVar and Chan?
    • A) Both are designed for memory management
    • B) MVar is used for synchronization, while Chan is for message passing
    • C) MVar is for parallel computation, while Chan is for lazy evaluation
    • D) MVar and Chan are interchangeable in Haskell

3. STM (Software Transactional Memory)

  1. What does STM stand for in Haskell?
    • A) Synchronous Transaction Management
    • B) Software Transactional Memory
    • C) Single-threaded Memory
    • D) Systematic Task Management
  2. What is the primary goal of STM in Haskell?
    • A) To simplify concurrent programming by making it easier to handle shared memory
    • B) To ensure that all threads run in parallel
    • C) To avoid using memory in concurrent tasks
    • D) To support lazy evaluation in multi-core systems
  3. Which function in Haskell is used to begin a transaction in STM?
    • A) atomically
    • B) forkSTM
    • C) runSTM
    • D) executeTransaction
  4. What is a key advantage of using STM in Haskell?
    • A) It avoids deadlocks by using retry mechanisms
    • B) It ensures maximum CPU utilization
    • C) It improves sequential performance
    • D) It limits memory usage in multi-core systems
  5. Which of the following is a key feature of STM in Haskell?
    • A) Non-blocking synchronization
    • B) Transactional isolation of state changes
    • C) Automatic garbage collection
    • D) Direct manipulation of hardware

4. Basic Parallel Computation and Lazy Parallelism

  1. What does parallelism mean in Haskell?
    • A) Running multiple tasks on different processors at the same time
    • B) Performing tasks in sequence but managing them efficiently
    • C) Lazy evaluation of tasks
    • D) Using a single processor to manage multiple threads
  2. Which function in Haskell can be used for parallel computations?
    • A) par
    • B) forkIO
    • C) split
    • D) runTask
  3. What is lazy parallelism in Haskell?
    • A) Delaying computations until their results are needed
    • B) Automatically distributing tasks across multiple processors
    • C) Using STM to manage parallel tasks
    • D) Running computations in sequence for better performance
  4. How does Haskell achieve parallelism without explicit multi-threading?
    • A) Using lazy evaluation and parallel combinators
    • B) Manually splitting tasks into threads
    • C) Relying on external libraries for parallelism
    • D) Using STM for automatic parallel execution
  5. In Haskell, the par function is used for:
    • A) Parallelizing computations in a lazy manner
    • B) Running tasks sequentially
    • C) Synchronizing multiple threads
    • D) Managing shared state between threads

Answer Key:

QnoAnswer (Option with Text)
1B) Managing multiple tasks simultaneously without direct synchronization
2A) Cooperative multitasking
3D) MVar
4B) Efficient management of multiple independent tasks
5B) Using forkIO to create new threads
6A) It creates a new thread that runs concurrently
7B) MVar
8A) Storing values in a thread-safe way
9B) Passing messages between threads
10B) MVar is used for synchronization, while Chan is for message passing
11B) Software Transactional Memory
12A) To simplify concurrent programming by making it easier to handle shared memory
13A) atomically
14A) It avoids deadlocks by using retry mechanisms
15B) Transactional isolation of state changes
16A) Running multiple tasks on different processors at the same time
17A) par
18A) Delaying computations until their results are needed
19A) Using lazy evaluation and parallel combinators
20A) Parallelizing computations in a lazy manner

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top