CS 3377 Final

Cards (119)

  • [APUE11] Which of the following functions is used to create a thread?
    pthread_detach
    pthread_exit
    pthread_join
    pthread_self
    pthread_create
    pthread_create
  • [APUE11] Consider the following function to be run by a thread.
    void
    PrintHello(voidthreadid) { . . . }
    pthread_t tid;
    int rc;

    Which of the following statement is correct to create a thread that executes a function called PrintHello?

    rc = pthread_init(&tid, NULL, PrintHello, (void *)1);
    rc = pthread_create(tid, NULL, *PrintHello, 1);
    rc = pthread_create(&tid, NULL, &PrintHello, (void *)1);
    rc = pthread_create(&tid, NULL, PrintHello, (void *)1);
    rc = pthread_new(&tid, NULL, PrintHello, 1);rc = pthread_create(&tid, NULL, PrintHello, (void *)1);
  • [APUE11] When a thread is terminated, a thread can arrange for a function to be called when it exits. Which of the following statement is not correct?
    This function is known as thread cleanup handler.
    More than one function can be established and registered for a thread for its exit.
    This function is recorded in a stack
    This function will be executed (in reverse order, if more than one, of the registration).
    The process runs this function for the thread being terminated.
    The process runs this function for the thread being terminated.
  • [APUE11] Spin locks are often used as low-level primitives to implement other types of locks, and can be implemented efficiently using ___ instruction.
    atomic
    swap-and-set
    test-and-set
    spin-and-set
    mutual-exclusive
    test-and-set
  • [APUE11] Spin locks are useful when running in real-time scheduling class that doesn't allow ____.
    preemption
    single thread of control
    reentrant processes
    concurrency
    mutex
    time-sharing
    preemption
  • [APUE11] pthread_join function acts as ___ to allow one thread to wait until another thread exits.
    lock
    mutex
    conditional variable
    spin lock
    barrier
    semaphore
    barrier
  • [APUE11] When the default action initialed by a thread is to terminate the process of this thread, what is expected?
    A signal sent to a thread will terminate the entire process.
    A signal sent to the process will terminate all the threads of the process.
    A signal sent to a thread to be terminated but it is ignored by the process.
    This is an invalid action which a thread cannot initiate.
    A signal sent to a thread will terminate the entire process.
  • [APUE11] A ___ is basically a lock that a thread does set (lock) before accessing a shared resource and release(unlock) when we're done.
    bit-lock
    mutex
    conditional variable
    semaphore
    message queue
    mutex
  • [APUE11] Which of the following functions is used by a thread to obtain its ID?
    pthread_detach
    pthread_exit
    pthread_join
    pthread_self
    pthread_create
    pthread_self
  • [APUE11] ___ is like a mutex, except that instead of blocking a process by sleeping, the process is blocked by busy-waiting until the lock can be acquired.
    simple-lock
    busy-mutex
    wait-lock
    conditional variable
    spin-lock
    spin-lock
  • [APUE11] Consider the following statements for a lock in thread programming.
    pthread_mutex_t MutexLock;
    pthread_mutex_init(&MutexLock, NULL);

    Which of the following statement will lock the mutex called MutexLock?
    pthread_mutex_lock(&MutexLock);
  • [APUE11] What is a thread primitive, corresponding to fork for process.
    pthread_create
    pthread_exit
    pthread_join
    pthread_cleanup_push
    pthread_self
    pthread_cancel
    pthread_create
  • [APUE11] Spin locks are useful when used in a(n) ___ kernel: besides providing a mutual exclusion mechanism, they block interrupts so an interrupt handler can't deadlock the system by trying to acquire a spin lock that is already locked.
    preemptive
    nonpreemptive
    reentrant
    nonretentrant
    concurrent
    time-sharing
    nonpreemptive
  • [APUE11] A thread can arrange for functions to be called when it exits, similar to the way that the atexit function.
    pthread_create
    pthread_exit
    pthread_join
    pthread_cleanup_push
    pthread_self
    pthread_cancel
    pthread_cleanup_push
  • [APUE11] ___ is a synchronization mechanism that can be used to coordinate multiple threads working in parallel. This allows each thread to wait until all cooperating threads have reached the same point, and then continue executing from there.
    lock
    mutex
    conditional variable
    spin lock
    barrier
    semaphore
    barrier
  • [APUE11] If any thread within a process calls exit, _Exit, or _exit, then what is expected?
    the thread called exit will terminate.
    the thread and its children will terminate.
    the entire process (with all of its threads) terminates.
    no effect to the thread as exit is only for process.
    the entire process (with all of its threads) terminates.
  • [APUE11] If a thread knows that no thread cares about its return value, then which of the following functions does it call to indicate that resources associated with it can be released on termination?
    pthread_detach
    pthread_exit
    pthread_join
    pthread_self
    pthread_create
    pthread_detach
  • [APUE11] What is a thread primitive, corresponding to waitpid for process.
    pthread_create
    pthread_exit
    pthread_join
    pthread_cleanup_push
    pthread_self
    pthread_cancel
    pthread_join
  • [APUE11] Which of the following items is shared by all thread in a process?
    Stack
    Program Counter
    File descriptors
    errno variable
    File descriptors
  • [APUE11] When multiple threads of control share the same memory (a shared variable), one needs to make sure that each thread sees a consistent view of its data. Which of the following statements is not correct? Select one best answer.
    If each thread uses variables while other threads don't read or modify, no consistency problems will exist.
    If a shared variable is read-only, there is no consistency problem.
    When a thread can modify a variable that other threads can read or modify, then inconsistency problem can occur.
    While a thread reads a variable, there is no consistency problem.
    While a thread reads a variable, there is no consistency problem.
  • [APUE11.6] ____ is another synchronization mechanism available to threads. These synchronization objects provide a place for threads to rendezvous. When used with mutexes, it allows threads to wait in a race-free way for arbitrary conditions to occur.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    socket
    spin lock
    conditional variable
  • [APUE11.6] When multiple threads of control share the same memory, each thread should see a consistent view of its data.
    Which one of the following statements is NOT correct?
    If each thread uses variables that other threads don't read or modify, there is no consistency problem.
    A variable which is read-only could create a consistency problem with more than one thread reading its value at the same time.
    When one thread can modify a variable that other threads can read or modify, there is a need to synchronize the threads to ensure that they don't use an invalid value when accessing the variable's memory contents.
    When one thread modifies a variable, other threads can potentially see inconsistencies when reading the value of that variable.
    On processor architectures in which the modification takes more than one memory cycle, this can happen when the memory read is interleaved between the memory write cycles.
    A variable which is read-only could create a consistency problem with more than one thread reading its value at the same time.
  • [APUE11.6] When we use more than one mutex in our programs, a(n) ____ can occur if we allow one thread to hold a mutex and block while trying to lock a second mutex at the same time that another thread holding the second mutex tries to lock the first mutex. Neither thread can proceed, because each needs a resource that is held by the other, so we have a(n) ____.
    mutex locking
    deadlock
    mutex interruption
    spin
    busy-wait
    threshing
    deadlock
  • [APUE11.6] When a reader-writer lock is ____ locked, only one thread to ____ can have it while all threads attempting to read must wait until it is unlocked.
    allocate
    free
    access
    read
    update
    write
    write
  • [APUE11.6] One additional mutex primitive allows us to bound the time that a thread blocks when a mutex it is trying to acquire is already locked. The ____ function is equivalent to pthread_mutex_lock, but if the timeout value is reached, it will return the error code ETIMEDOUT without locking the mutex.
    pthread_mutex_time
    pthread_mutex_timelock
    pthread_mutex_timedlock
    pthread_mutex_timeset
    pthread_mutex_timelimit
    pthread_mutex_timedlock
  • [APUE11.6] _____ is well suited for situations in which data structures are read more often than they are modified. When a(n) ____ is held in write mode, the data structure it protects can be modified safely, since only one thread at a time can hold the lock in write mode.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    socket
    spin lock
    reader-writer lock
  • [APUE11.6] At user level, ____ is not as useful unless you are running in a real-time scheduling class that doesn't allow preemption. User-level threads running in a time-sharing scheduling class can be descheduled when their time quantum expires or when a thread with a higher scheduling priority becomes runnable. In these cases, if a thread is holding ____, it will be put to sleep and other threads blocked on the lock will continue waiting longer than intended.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    spinlock
    spinlock
  • [APUE11.6] While it is set, any other thread that tries to set it will block until we release it. If more than one thread is blocked when we unlock the ____, then all threads blocked on the lock will be made runnable, and the first one to run will be able to set the lock. The others will see that the ____ is still locked and go back to waiting for it to become available again. In this way, only one thread will proceed at a time.
    barrier
    conditional variable
    deadlock
    livelock
    message queue
    mutex
    pipe
    semaphore
    mutex
  • [APUE11.6] Assume that you have two mutexes, A and B, that you need to lock at the same time. If all threads always lock mutex A before mutex B, ____.
    Deadlocks can be avoided with these two mutexes.
    It is still possible to have a deadlock with these two mutexes.
    It is still possible to have a deadlock with the mutex A.
    It is still possible to have a deadlock with the mutex B.
    None of the above is correct.
    Deadlocks can be avoided with these two mutexes.
  • [APUE11.6] If we allocate the mutex dynamically (by calling malloc, for example), then we need to call _____ before freeing the memory.
    pthread_mutex_destroy
    pthread_mutex_deallocate
    pthread_mutex_free
    pthread_mutex_exit
    pthread_mutex_return
    pthread_mutex_destroy
  • [APUE11.6] ____ is useful when used in a nonpreemptive kernel: besides providing a mutual exclusion mechanism, they block interrupts so an interrupt handler can't deadlock the system by trying to acquire a spin lock that is already locked (think of interrupts as another type of preemption). In these types of kernels, interrupt handlers can't sleep, so the only synchronization primitives they can use are ____.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    spinlock
    spinlock
  • [APUE11.6] Only one thread at a time can hold a(n) ____ in write mode, but multiple threads can hold a(n) ____ in read mode at the same time.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    socket
    signal
    reader-writer lock
  • [APUE11.6] A reader-writer lock is initialized by calling ____.
    pthread_reader_writer_lock_init
    pthread_rw_lock_init
    pthread_rwlock_init
    pthread_readwritelock_init
    pthread_rdwtlock_init
    pthread_rwlock_init
  • [APUE11.6] A thread will ____ if it tries to lock the same mutex twice.
    allocate mutex
    deadlock itself
    free mutex first
    interrupt itself
    spin itself
    unlock mutex
    deadlock itself
  • [APUE11.6] The pthread_join function acts as a ____ to allow one thread to wait until another thread exits.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    spinlock
    barrier
  • [APUE11.6] To lock a reader-writer lock in read mode, we call ____.
    pthread_rwlock_read
    pthread_readlock
    pthread_writelock
    pthread_rwlock_rdlock
    pthread_rwlock_readlock
    pthread_rwlock_rdlock
  • [APUE11.6] The condition is the state of the work queue. We protect the condition with a mutex and evaluate the condition in a while loop. When we put a message on the work queue, we need to hold the mutex, but we don't need to hold the mutex when we signal the waiting threads. As long as it is okay for a thread to pull the message off the queue before we call a signal, we can do this after releasing the mutex. Since we check the condition in a while loop, this doesn't present a problem; a thread will wake up, find that the queue is still empty, and go back to waiting again. If the code couldn't tolerate this race, we would need to hold the mutex when we signal the threads. This is about ____ mechanism.
    barrier
    conditional variable
    mutex
    message queue
    reader-writer lock
    semaphore
    socket
    signal
    conditional variable
  • [APUE11.6] With multiple threads of control, we can design our programs to do more than one thing at a time within a single process, with each thread handling a separate task. This approach can have several benefits.
    Which one of the following statements is NOT correct?
    Some problems can be partitioned so that overall program throughput can be improved.
    A single-threaded process with multiple tasks cannot serializes those tasks.
    The processing of independent tasks with multiple threads can be interleaved by assigning a separate thread per task.
    Interactive programs can improve response time with separate user-input-task thread and output-task thread from the other parts of the program.
    Multithreaded programming can be associated with multiprocessor or multicore systems.
    The benefits of a multithreaded programming model can be realized even if your program is running on a uniprocessor.
    A program can be simplified using threads regardless of the number of processors.
    A single-threaded process with multiple tasks cannot serializes those tasks.
  • [APUE11.6] When a reader-writer lock is ____ locked, all threads attempting to ___ are given access, but all threads attempting to write must wait until the lock is released by all threads in ____.
    allocate
    free
    access
    read
    update
    write
    read
  • [APUE11.6] The _____ mechanism works only if we design our threads to follow the same data-access rules. The operating system doesn't serialize access to data for us. If we allow one thread to access a shared resource without first acquiring a lock, then inconsistencies can occur even though the rest of our threads do acquire the lock before attempting to access the shared resource.
    asynchronization
    blocking
    mutual-exclusion
    nonblocking
    preemption
    resource-sharing
    synchronization
    mutual-exclusion