MCQs on Advanced Concurrency and Parallelism | Haskell

Concurrency and parallelism are essential for achieving high performance in modern computing, especially when working with Haskell. This set of 30 multiple-choice questions (MCQs) covers advanced topics like Software Transactional Memory (STM), parallel Haskell using par and pseq, the Actor model, and distributed systems. These concepts are crucial for building efficient, scalable applications that can handle complex computations.


Topics:

Software Transactional Memory (STM)

  1. Which of the following is the key feature of Software Transactional Memory (STM)? a) Lock-based synchronization
    b) Transactional consistency
    c) Multithreaded computation
    d) Data immutability
  2. In Haskell’s STM, which type represents a transaction? a) MVar
    b) TVar
    c) IORef
    d) STRef
  3. Which STM operation is used to start a new transaction in Haskell? a) atomically
    b) forkIO
    c) newTVarIO
    d) retry
  4. In STM, the retry function causes the transaction to: a) Commit immediately
    b) Rollback and retry
    c) Exit the transaction
    d) Suspend the transaction
  5. What is the default behavior of Haskell’s STM when a transaction cannot immediately complete? a) Immediate rollback
    b) Retry at a later time
    c) Block indefinitely
    d) Force a deadlock
  6. Which of the following functions is used to commit a transaction in STM? a) commit
    b) atomic
    c) atomically
    d) commitSTM
  7. How does STM in Haskell differ from traditional lock-based concurrency mechanisms? a) STM uses locks
    b) STM provides transactional guarantees without locks
    c) STM avoids multi-threading
    d) STM restricts the number of threads
  8. What happens if two STM transactions attempt to modify the same TVar at the same time? a) Both transactions succeed
    b) One transaction succeeds, the other is aborted
    c) Both transactions block indefinitely
    d) A deadlock occurs
  9. Which Haskell package provides the STM module for concurrency? a) Control.Concurrent
    b) Control.Monad
    c) Control.Concurrent.STM
    d) Control.Applicative
  10. What is the primary advantage of STM over traditional locks in concurrent programming? a) Better performance
    b) Simpler code
    c) Avoidance of deadlock
    d) Easier debugging

Parallel Haskell and par/pseq for Parallel Computation

  1. What is the purpose of par in Haskell? a) Sequential computation
    b) Parallelizing pure computations
    c) Managing stateful computations
    d) Handling IO operations
  2. In Haskell, what is the function pseq used for? a) For parallel computation
    b) For sequential evaluation
    c) For creating threads
    d) For managing mutable variables
  3. Which of the following is true about the relationship between par and pseq? a) par ensures order of execution
    b) pseq guarantees parallel execution
    c) par creates parallel threads, pseq enforces evaluation order
    d) par is for IO operations, pseq is for STM
  4. What does the par combinator achieve in Haskell? a) It forces strict evaluation
    b) It signals that the computation can be performed in parallel
    c) It handles side-effects
    d) It suspends computation until needed
  5. Which type of computation does pseq help with in a parallel setting? a) Lazy evaluation
    b) Strict evaluation
    c) Deadlock prevention
    d) IO operations
  6. What is the result of using par without pseq in a parallel computation? a) A deadlock
    b) Undefined behavior
    c) Non-deterministic evaluation order
    d) Immediate computation
  7. In which kind of computation is the combination of par and pseq most useful? a) Parallel recursive computation
    b) Sequential data transformation
    c) Single-threaded execution
    d) IO-bound tasks
  8. How does parallel Haskell differ from traditional parallel programming models? a) Haskell does not support parallelism
    b) Haskell uses functional constructs for parallelism
    c) Haskell relies solely on multi-core processors
    d) Haskell only supports parallel loops
  9. What does the Control.Parallel module provide in Haskell? a) Transactional memory support
    b) Parallel execution functions like par and pseq
    c) IO and mutable state
    d) Actor-based concurrency models
  10. Which of the following describes the evaluation strategy for parallel Haskell code? a) Eager evaluation
    b) Lazy evaluation
    c) Strict evaluation
    d) Dynamic evaluation

Actors and Message-Passing Concurrency Models

  1. Which of the following is a key concept in the Actor model of concurrency? a) Shared memory
    b) Message-passing between independent agents
    c) Locking mechanisms
    d) Centralized control
  2. In the Actor model, each actor is responsible for: a) Sending and receiving messages
    b) Managing shared state
    c) Coordinating threads
    d) Synchronizing memory access
  3. Which library provides actor-based concurrency in Haskell? a) Control.Concurrent
    b) ActorModel
    c) Control.Concurrent.Actor
    d) HAppS
  4. What is the fundamental communication mechanism in the Actor model? a) Shared variables
    b) Direct function calls
    c) Message-passing
    d) Memory-mapped files
  5. In the Actor model, what happens when an actor receives a message? a) It updates its own state and sends a response
    b) It immediately terminates
    c) It blocks all other actors
    d) It suspends other actors until completion
  6. What does the Actor model avoid in comparison to traditional multi-threaded programming? a) Deadlock
    b) Race conditions
    c) Data-sharing between threads
    d) Thread synchronization
  7. How do actors in the Actor model manage their state? a) Through mutable global variables
    b) Through message queues
    c) By synchronizing with other actors
    d) By having local private states
  8. In Haskell, which function is typically used to send messages to an actor? a) sendMessage
    b) actorSend
    c) tell
    d) postMessage
  9. Which of the following best describes the Actor model’s suitability for concurrent applications? a) Ideal for applications with shared memory
    b) Useful for applications with isolated processes communicating via messages
    c) Best suited for sequential computation
    d) Designed for applications with minimal communication between processes
  10. What is a potential disadvantage of the Actor model in Haskell? a) Limited scalability
    b) High overhead in managing message queues
    c) Lack of support for parallel execution
    d) Complex state management

Answer Key:

QnoAnswer
1b) Transactional consistency
2b) TVar
3a) atomically
4b) Rollback and retry
5b) Retry at a later time
6c) atomically
7b) STM provides transactional guarantees without locks
8b) One transaction succeeds, the other is aborted
9c) Control.Concurrent.STM
10c) Avoidance of deadlock
11b) Parallelizing pure computations
12b) For sequential evaluation
13c) par creates parallel threads, pseq enforces evaluation order
14b) It signals that the computation can be performed in parallel
15b) Strict evaluation
16c) Non-deterministic evaluation order
17a) Parallel recursive computation
18b) Haskell uses functional constructs for parallelism
19b) Parallel execution functions like par and pseq
20b) Lazy evaluation
21b) Message-passing between independent agents
22a) Sending and receiving messages
23c) Control.Concurrent.Actor
24c) Message-passing
25a) It updates its own state and sends a response
26c) Data-sharing between threads
27d) By having local private states
28c) tell
29b) Useful for applications with isolated processes communicating via messages
30b) High overhead in managing message queues

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