1. Home
  2. Explore
  3. Computer Science
  4. Concurrency in Operating Systems

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Concurrency in Operating Systems

  • 82Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Concurrency Scheduling

Which program design best supports concurrency as described in the lecture?

82 questions

  1. 1

    Which program design best supports concurrency as described in the lecture?

    1. A

      Divide the program into order-independent parts that can run without interfering

    2. B

      Divide the program into parts that must finish in a fixed sequence

    3. C

      Combine all operations into one part that waits for every input

    4. D

      Run multiple copies of one instruction stream that share no CPU time

    Correct answer
    A

    Divide the program into order-independent parts that can run without interfering

    Explanation

    Concurrency involves decomposing a program into chunks that can run at the same time without depending on a particular order or interfering with one another.

  2. 2

    Which statement about processes on UNIX is supported by the lecture?

    1. A

      Multiple processes, including copies of the same program, can run simultaneously

    2. B

      A process must finish before another process can begin running

    3. C

      Processes can run simultaneously only if each has a separate operating system

    4. D

      Only one process can exist for a given program at a time

    Correct answer
    A

    Multiple processes, including copies of the same program, can run simultaneously

    Explanation

    UNIX allows multiple processes to run, including multiple copies of the same program, with CPU time shared among them.

  3. 3

    How can concurrency improve CPU efficiency when one process is waiting for input or output?

    1. A

      The waiting process automatically becomes a separate CPU core

    2. B

      Another process can use the CPU while the first process waits

    3. C

      The waiting process continues using the CPU while the device responds

    4. D

      The operating system pauses all other processes until the input or output finishes

    Correct answer
    B

    Another process can use the CPU while the first process waits

    Explanation

    If a process is waiting for input or output, another process can use the CPU, making better use of available processing time.

  4. 4

    What does multiprogramming mean in the lecture?

    1. A

      The CPU executes every ready process at exactly the same instant

    2. B

      One process is divided into user-level threads only

    3. C

      More than one process can be ready to execute

    4. D

      More than one process must execute on separate physical CPUs

    Correct answer
    C

    More than one process can be ready to execute

    Explanation

    Multiprogramming means that more than one process can be ready to execute, with the system switching among processes when appropriate.

  5. 5

    In the lecture's description of multiprogramming, what can prompt a process to hand off control?

    1. A

      The process becomes blocked while waiting for an input/output operation

    2. B

      The process reaches a formatted-print library function

    3. C

      The process creates another copy of its source code

    4. D

      The process receives a new global variable

    Correct answer
    A

    The process becomes blocked while waiting for an input/output operation

    Explanation

    A process blocked in an input/output operation cannot continue, so another process can be switched in to run.

  6. 6

    What is a context switch?

    1. A

      Moving a process's data from the heap to its stack

    2. B

      Changing a user-level thread into a separate program

    3. C

      Changing a process's library function into a system call

    4. D

      Changing from one process to another

    Correct answer
    D

    Changing from one process to another

    Explanation

    A context switch is the act of switching execution from one process to another.

  7. 7

    How does timesharing differ from multiprogramming in the lecture?

    1. A

      Timesharing requires multiple physical CPUs, while multiprogramming requires one

    2. B

      Timesharing divides CPU time among processes, while multiprogramming can switch when a process blocks

    3. C

      Timesharing runs only blocked processes, while multiprogramming runs only completed processes

    4. D

      Timesharing applies only to threads, while multiprogramming applies only to library functions

    Correct answer
    B

    Timesharing divides CPU time among processes, while multiprogramming can switch when a process blocks

    Explanation

    Timesharing splits CPU time among processes to create the illusion of simultaneous execution; multiprogramming can let another process run when one becomes blocked.

  8. 8

    What does multiprocessing mean, in contrast to multiprogramming?

    1. A

      Several processes are ready, but only one can ever execute

    2. B

      Several processes are actually executing at the same time

    3. C

      A single process takes turns among its library functions

    4. D

      The operating system schedules only processes that are blocked

    Correct answer
    B

    Several processes are actually executing at the same time

    Explanation

    Multiprocessing means executing multiple processes at the same time, as can happen on a CPU with multiple cores.

  9. 9

    What role can multiple CPU cores play in multiprocessing?

    1. A

      Each core can execute processing from a program, allowing work to run simultaneously

    2. B

      Each core stores a separate copy of the operating system scheduler

    3. C

      Each core prevents its processes from sharing any data

    4. D

      Each core turns a system call into a library function

    Correct answer
    A

    Each core can execute processing from a program, allowing work to run simultaneously

    Explanation

    The lecture describes CPU cores as acting like mini CPUs that can each run processing, enabling multiple processes or threads to execute at once.

  10. 10

    What is the kernel, according to the lecture?

    1. A

      A user-level thread that executes only input and output operations

    2. B

      A file used by processes to signal that a resource is available

    3. C

      A library of application functions that cannot interact with hardware

    4. D

      The central part of the operating system, containing core routines and hardware-abstraction support

    Correct answer
    D

    The central part of the operating system, containing core routines and hardware-abstraction support

    Explanation

    The kernel is the operating system's central part, where fundamental routines and hardware-abstraction layers that communicate with hardware through drivers reside.

  11. 11

    What is one of the kernel's primary duties described in the lecture?

    1. A

      Preventing processes from making requests for operating-system services

    2. B

      Assigning every process a separate physical CPU

    3. C

      Providing a scheduler to distribute CPU time among processes or threads

    4. D

      Converting all user-level threads into library functions

    Correct answer
    C

    Providing a scheduler to distribute CPU time among processes or threads

    Explanation

    The scheduler is described as one of the kernel's primary duties; it allocates CPU time according to its priorities or fairness policy.

  12. 12

    How does a program typically request that the kernel perform an operation on its behalf?

    1. A

      By creating a user-level thread

    2. B

      By declaring a global variable

    3. C

      By making a system call

    4. D

      By returning from its main function

    Correct answer
    C

    By making a system call

    Explanation

    A system call is a request made to the kernel to perform an operation on behalf of a process.

  13. 13

    What happens to a process when it makes a system call, as described in the lecture?

    1. A

      The process automatically divides itself into multiple kernel threads

    2. B

      The process continues past the call while the operating system performs it later

    3. C

      The process is converted into a library function and keeps running uninterrupted

    4. D

      Control passes to the operating system, and the process commonly blocks until the call returns

    Correct answer
    D

    Control passes to the operating system, and the process commonly blocks until the call returns

    Explanation

    A system call interrupts the process's flow and passes control to the operating system. The process commonly blocks and does not continue until the call returns.

  14. 14

    Why might a process block while performing a read or write system call?

    1. A

      The operating system cannot perform input or output for processes

    2. B

      The call changes every thread in the process into a separate program

    3. C

      It is waiting for an operation, such as obtaining or writing data, that it cannot carry out by itself

    4. D

      The call requires the process to delete its stack before continuing

    Correct answer
    C

    It is waiting for an operation, such as obtaining or writing data, that it cannot carry out by itself

    Explanation

    Read and write are typical system calls because the process may need the operating system to carry out input or output; it can block while that operation is handled.

  15. 15

    Which example is presented as a C library function rather than a system call?

    1. A

      Passing control to the operating system for a service

    2. B

      Calculating a square root

    3. C

      Requesting data from a storage device

    4. D

      Writing data to a device

    Correct answer
    B

    Calculating a square root

    Explanation

    The lecture gives calculating a square root and formatted printing as examples of C library functions, unlike input/output system calls.

  16. 16

    How does the lecture contrast a C library function with a system call?

    1. A

      A library function can be used only by the kernel, while a system call can be used only by a process

    2. B

      A library function creates a new process, while a system call creates a new global variable

    3. C

      A library function does not make the same operating-system service request that can block a process

    4. D

      A library function always blocks, while a system call never affects process execution

    Correct answer
    C

    A library function does not make the same operating-system service request that can block a process

    Explanation

    The lecture describes C library functions as operations such as square-root calculation or formatted printing, in contrast to system calls that pass control to the operating system and commonly block.

  17. 17

    What determines how the scheduler distributes CPU time, according to the lecture?

    1. A

      The order in which source files were written

    2. B

      Its programmed priorities or fairness policy

    3. C

      Whether a process uses formatted output

    4. D

      The number of global variables in each process

    Correct answer
    B

    Its programmed priorities or fairness policy

    Explanation

    The scheduler distributes prioritized or fair CPU time based on its priorities and how it has been programmed.

  18. 18

    Why can race conditions be difficult to detect during testing?

    1. A

      They may require a rare combination of events and timing to occur

    2. B

      They occur only when a program has no shared resources

    3. C

      They can be detected only by examining source-code formatting

    4. D

      They always produce the same visible failure on every run

    Correct answer
    A

    They may require a rare combination of events and timing to occur

    Explanation

    A race condition may arise only under a special set of circumstances or a particular relative timing, so testing may not expose it reliably.

  19. 19

    Which description best captures a race condition as defined in the lecture?

    1. A

      A process that waits until a system call returns

    2. B

      A flaw where a program always produces the same result regardless of event timing

    3. C

      A flaw where the output depends unexpectedly and critically on the relative timing of events

    4. D

      A scheduler policy that gives each process equal CPU time

    Correct answer
    C

    A flaw where the output depends unexpectedly and critically on the relative timing of events

    Explanation

    A race condition is a flaw in which the output has an unexpected critical dependence on the relative timing of events.

  20. 20

    In the ATM example, how can two simultaneous withdrawals incorrectly leave an account balance too high?

    1. A

      Each process subtracts from the other's local stack and doubles the account balance

    2. B

      The bank account refuses the first write but accepts both reads

    3. C

      Both processes read the same starting balance, subtract separately, and overwrite one another's update

    4. D

      The operating system converts both withdrawals into deposits

    Correct answer
    C

    Both processes read the same starting balance, subtract separately, and overwrite one another's update

    Explanation

    If both ATM processes read the same balance before either writes, each can subtract from that original value and then write it back, causing one withdrawal's update to be lost.

  21. 21

    What condition makes the ATM balance example a race condition?

    1. A

      The final balance depends on the timing and ordering of the two processes' reads and writes

    2. B

      Each withdrawal has a fixed amount

    3. C

      The two ATMs are located in different cities

    4. D

      The account balance is stored by the bank

    Correct answer
    A

    The final balance depends on the timing and ordering of the two processes' reads and writes

    Explanation

    The race arises because the result depends on the relative timing of concurrent reads and writes to the same account balance.

  22. 22

    What general security risk can arise when concurrent processes share data or resources?

    1. A

      The scheduler may be unable to identify any running process

    2. B

      The processes are forced to use separate operating systems

    3. C

      A process may gain access to sensitive information that should be restricted

    4. D

      Every shared variable is automatically deleted

    Correct answer
    C

    A process may gain access to sensitive information that should be restricted

    Explanation

    Sharing data or resources can be a security problem if one process can access sensitive data that should not be available to it.

  23. 23

    What lesson does the Therac-25 example illustrate about safety interlocks?

    1. A

      Hardware interlocks make it impossible for people to enter information too quickly

    2. B

      The system was safe because its errors appeared on a screen

    3. C

      Removing hardware interlocks and relying only on software interlocks can contribute to catastrophic failures

    4. D

      Software interlocks always prevent race conditions without testing

    Correct answer
    C

    Removing hardware interlocks and relying only on software interlocks can contribute to catastrophic failures

    Explanation

    The lecture links the Therac-25 disaster to designers removing hardware interlocks and relying on software interlocks, alongside a system vulnerable to rapid user input and overlooked errors.

  24. 24

    In the Therac-25 account, what assumption about user behavior contributed to the problem?

    1. A

      The system assumed users would never read messages on the screen

    2. B

      The system relied on users waiting for the machine to shut down between keystrokes

    3. C

      The system relied on users entering information slowly, but users became faster with experience

    4. D

      The system assumed users would enter information only through hardware interlocks

    Correct answer
    C

    The system relied on users entering information slowly, but users became faster with experience

    Explanation

    The lecture says the designers counted on users being slow, but users became faster and could move past errors displayed on the screen.

  25. 25

    When does the lecture say access control is necessary for a concurrent resource?

    1. A

      Only when the resource is a C library function

    2. B

      When multiple processes may access it and at least one may write to it

    3. C

      Whenever two processes exist, even if neither can access shared data

    4. D

      Only when every process reads the resource but none can write

    Correct answer
    B

    When multiple processes may access it and at least one may write to it

    Explanation

    The lecture calls for access control when concurrency allows multiple processes to access a resource and at least one of them may write to it.

  26. 26

    While one process is writing to a shared resource, what access rule does the lecture recommend?

    1. A

      Other processes may access it whenever they use a different CPU core

    2. B

      Other processes may read it but must not write to it

    3. C

      Other processes may write to it but must not read it

    4. D

      No other process should read or write the resource until the write is complete

    Correct answer
    D

    No other process should read or write the resource until the write is complete

    Explanation

    The lecture says that while one process is writing, no other process should access the resource for either reading or writing until the write finishes.

  27. 27

    What is the purpose of a lock in the lecture's description of access control?

    1. A

      It ensures the scheduler runs one process forever

    2. B

      It automatically repairs inconsistent data after a race

    3. C

      It allows every process to write to a resource simultaneously

    4. D

      It restricts access to a resource to the process that owns the lock

    Correct answer
    D

    It restricts access to a resource to the process that owns the lock

    Explanation

    A lock protects a resource by allowing the process that owns the lock to access it while excluding other processes.

  28. 28

    How can a lock-file approach indicate that a resource is already locked?

    1. A

      A process renames its main function to match the resource

    2. B

      A process attempts to create a known lock file and treats its existing presence as another process's lock

    3. C

      A process reads the resource and checks whether its value is zero

    4. D

      A process creates a new CPU core and assigns the resource to it

    Correct answer
    B

    A process attempts to create a known lock file and treats its existing presence as another process's lock

    Explanation

    In the example, a process tries to create a known lock file and fails if it already exists; its presence indicates that another process has locked the resource.

  29. 29

    What does the sample lock-file loop do after discovering that the lock file already exists?

    1. A

      It terminates every process using the resource

    2. B

      It converts the lock file into a thread identifier

    3. C

      It sleeps briefly and tries again in a later loop iteration

    4. D

      It assumes the resource is unlocked and writes immediately

    Correct answer
    C

    It sleeps briefly and tries again in a later loop iteration

    Explanation

    The sample code sleeps for a short time when the lock file already exists, then retries on the next loop iteration.

  30. 30

    Why can threads communicate more simply than separate processes, as described in the lecture?

    1. A

      Separate processes always share their stacks automatically

    2. B

      Threads in the same process share code, heap memory, and global or static data

    3. C

      Threads each have a separate operating system kernel

    4. D

      Threads never need memory to communicate

    Correct answer
    B

    Threads in the same process share code, heap memory, and global or static data

    Explanation

    Threads share their program code, heap, and data such as global and static variables, which makes communication simpler than interprocess communication.

  31. 31

    Which memory area does each thread have for its own function-call state and automatic variables?

    1. A

      Its own stack

    2. B

      A private copy of all global variables

    3. C

      A separate kernel

    4. D

      A separate copy of the process's entire heap

    Correct answer
    A

    Its own stack

    Explanation

    Each thread has its own stack to track function returns and automatic variables used as it executes.

  32. 32

    What does the lecture say about one thread's ability to access another thread's stack memory?

    1. A

      It can access that memory because the threads share the process's address space

    2. B

      It can access it only after creating a new process

    3. C

      It can never access that memory under any circumstances

    4. D

      It can access it only through a system call that copies the stack

    Correct answer
    A

    It can access that memory because the threads share the process's address space

    Explanation

    Although each thread has its own stack, the lecture notes that threads can access the stacks of other threads in the shared process memory.

  33. 33

    Why can switching between threads in one process be faster than switching between processes?

    1. A

      Threads have no execution state to preserve

    2. B

      Threads never require the scheduler to choose what runs

    3. C

      Threads share much of their process's data, so that memory need not be unloaded and loaded again

    4. D

      Threads run only as library functions and cannot be interrupted

    Correct answer
    C

    Threads share much of their process's data, so that memory need not be unloaded and loaded again

    Explanation

    The lecture attributes faster thread switching to shared process data that can remain in place rather than being unloaded and reloaded during a process switch.

  34. 34

    How can kernel-level threads provide true concurrent execution on a multicore CPU?

    1. A

      Different threads can be run on separate cores at the same time

    2. B

      Each thread must first become a separate operating system

    3. C

      Each thread is translated into a library function that runs sequentially

    4. D

      The scheduler prevents threads from running at the same time

    Correct answer
    A

    Different threads can be run on separate cores at the same time

    Explanation

    Kernel-level threads can be scheduled independently, allowing different threads to run simultaneously on separate CPU cores.

  35. 35

    What is one disadvantage of threads when they access shared resources without coordination?

    1. A

      The threads are automatically isolated from shared data

    2. B

      The scheduler must assign every thread a separate file

    3. C

      The process can no longer make system calls

    4. D

      Race conditions can occur

    Correct answer
    D

    Race conditions can occur

    Explanation

    Because threads can access shared resources, uncoordinated access can produce race conditions and other problems.

  36. 36

    What resource contention example is given for threads?

    1. A

      A thread's stack prevents every other thread from using the CPU

    2. B

      A library function forces all threads to use different source files

    3. C

      A system call involving a file can block access while another thread is using that file

    4. D

      A global variable prevents the operating system from starting the process

    Correct answer
    C

    A system call involving a file can block access while another thread is using that file

    Explanation

    The lecture notes that if one process is accessing a file, system calls may block another attempt to access the same file at the same time.

  37. 37

    Why can sharing between threads create a confidentiality concern?

    1. A

      Each thread's private stack is the only memory it can access

    2. B

      Sensitive data available in the shared process may be visible to threads that should not use it

    3. C

      A thread cannot access data created by another thread

    4. D

      Threads automatically encrypt all global variables

    Correct answer
    B

    Sensitive data available in the shared process may be visible to threads that should not use it

    Explanation

    Threads share process data, so sensitive information may be exposed to another thread that should not have access to it.

  38. 38

    Who controls kernel-level threads and allocates their CPU time?

    1. A

      The C preprocessor

    2. B

      The kernel, through its scheduler

    3. C

      The lock-file naming convention

    4. D

      Only the application through cooperative switching

    Correct answer
    B

    The kernel, through its scheduler

    Explanation

    Kernel-level threads are controlled by the kernel and receive CPU time through the scheduler.

  39. 39

    What distinguishes user-level threads from kernel-level threads?

    1. A

      User-level threads each have their own kernel scheduler

    2. B

      User-level threads must each run on a separate physical core

    3. C

      The kernel does not know about user-level threads, which are managed inside the process

    4. D

      Kernel-level threads exist only inside C library functions

    Correct answer
    C

    The kernel does not know about user-level threads, which are managed inside the process

    Explanation

    User-level threads are managed within a process and are not known to the kernel, unlike kernel-level threads.

  40. 40

    How does switching among user-level threads occur in the lecture's description?

    1. A

      Cooperatively, when the program chooses to switch its line of execution

    2. B

      Only when a thread makes a read system call

    3. C

      Automatically whenever a different CPU core becomes available

    4. D

      Only when the kernel scheduler detects each user-level thread separately

    Correct answer
    A

    Cooperatively, when the program chooses to switch its line of execution

    Explanation

    Switches between user-level threads are cooperative: the program itself determines when to move to another line of execution.

  41. 41

    What does the kernel see when a process switches among its user-level threads?

    1. A

      A separate kernel-level thread for every function call

    2. B

      A single running process

    3. C

      A sequence of system calls that must each block

    4. D

      A new operating-system process for every user-level thread

    Correct answer
    B

    A single running process

    Explanation

    From the kernel's perspective, user-level thread switching occurs inside a process, so the kernel sees a process rather than each user-level thread individually.

  42. 42

    What is a major disadvantage of user-level threads when a blocking system call occurs?

    1. A

      The system call automatically turns them into independent processes

    2. B

      The operating system must start a new kernel for each thread

    3. C

      The entire process containing them can be blocked

    4. D

      Only the thread that made the call can be unloaded while all others run on separate cores

    Correct answer
    C

    The entire process containing them can be blocked

    Explanation

    Because the kernel does not manage user-level threads separately, a blocking system call in the process can block the entire process.

  43. 43

    Why can a whole process containing user-level threads be pre-empted?

    1. A

      Each user-level thread always occupies a separate CPU core

    2. B

      User-level threads are system calls that must be completed immediately

    3. C

      A process containing user-level threads has no scheduler

    4. D

      The scheduler sees and schedules the process as a whole, not its internal user-level threads

    Correct answer
    D

    The scheduler sees and schedules the process as a whole, not its internal user-level threads

    Explanation

    The kernel schedules the process, not its internal user-level threads, so the scheduler can pre-empt or unload the whole process.

  44. 44

    Which statement about user-level threads is consistent with the lecture?

    1. A

      They can switch quickly, but are more difficult to use and are not provided by built-in UNIX libraries in the described way

    2. B

      They cannot be used for a program with multiple lines of execution

    3. C

      They always run on separate cores and cannot be pre-empted

    4. D

      They are controlled by the kernel scheduler and are easier to use than kernel threads

    Correct answer
    A

    They can switch quickly, but are more difficult to use and are not provided by built-in UNIX libraries in the described way

    Explanation

    The lecture says user-level thread switching can be very fast, but these threads are harder to use and their libraries are not built into UNIX in the same way as kernel-level threads.

  45. 45

    What does POSIX provide for UNIX-like systems?

    1. A

      A method for converting all system calls into library functions

    2. B

      A standard way for these systems to interact through common interfaces

    3. C

      A requirement that every process use a separate CPU

    4. D

      A rule that processes must share one global stack

    Correct answer
    B

    A standard way for these systems to interact through common interfaces

    Explanation

    POSIX is described as a consortium and standard for common interfaces that help UNIX-like operating systems interact consistently.

  46. 46

    What is the POSIX threads API used for?

    1. A

      Ensuring all threads run sequentially on one core

    2. B

      Replacing the kernel scheduler with a C preprocessor

    3. C

      Writing multithreaded applications on UNIX-like systems

    4. D

      Creating lock files without using operating-system services

    Correct answer
    C

    Writing multithreaded applications on UNIX-like systems

    Explanation

    The POSIX threads API is described as the standard way to write multithreaded applications on UNIX.

  47. 47

    Which header does the lecture identify for using POSIX thread functions?

    1. A

      stdio.h

    2. B

      stdlib.h

    3. C

      pthread.h

    4. D

      assert.h

    Correct answer
    C

    pthread.h

    Explanation

    The lecture says to include the pthread.h header to access the POSIX thread definitions.

  48. 48

    What is the purpose of adding the pthread option when compiling with gcc, as described?

    1. A

      To replace the program's main function with a thread

    2. B

      To link in the thread-related functions needed by the program

    3. C

      To convert every library function into a system call

    4. D

      To guarantee that threads complete in creation order

    Correct answer
    B

    To link in the thread-related functions needed by the program

    Explanation

    The lecture says the pthread option is needed when compiling and links in the code for functions defined elsewhere.

  49. 49

    What is the first argument to pthread_create used for?

    1. A

      Choosing how the scheduler divides CPU time

    2. B

      Selecting the function that the new thread starts in

    3. C

      Passing the thread's single optional argument

    4. D

      Storing the identifier of the newly created thread

    Correct answer
    D

    Storing the identifier of the newly created thread

    Explanation

    The first pthread_create argument points to the variable where the new thread's ID is written.

  50. 50

    What does the attributes argument to pthread_create provide?

    1. A

      A pointer to the thread's return value

    2. B

      A pointer to a structure containing thread option flags

    3. C

      The number of other threads that must finish first

    4. D

      The address of the function that created the process

    Correct answer
    B

    A pointer to a structure containing thread option flags

    Explanation

    The attributes argument points to a structure containing option flags; the lecture notes that programs commonly pass no special options.

  51. 51

    What does the start_routine argument to pthread_create specify?

    1. A

      The number of arguments the new thread can receive

    2. B

      The function where the new thread begins executing

    3. C

      The function that destroys the entire process

    4. D

      The thread ID that the new thread must use

    Correct answer
    B

    The function where the new thread begins executing

    Explanation

    The start_routine is a function pointer identifying where the new thread begins execution.

  52. 52

    How can a program pass several values to a thread's start routine when pthread_create accepts a single argument pointer?

    1. A

      Store every value in the thread ID

    2. B

      Place the values in a structure and pass a pointer to it

    3. C

      Pass each value as a separate pthread_create argument

    4. D

      Use the attributes argument as a list of integers

    Correct answer
    B

    Place the values in a structure and pass a pointer to it

    Explanation

    The arg parameter is a single argument, so the lecture recommends bundling multiple values into a structure and passing that structure.

  53. 53

    Why is a function name passed without parentheses as the start_routine argument?

    1. A

      The parentheses would destroy the thread ID

    2. B

      The function must be called by the scheduler before the thread is created

    3. C

      The function name is being passed as a C preprocessor constant

    4. D

      The function name can be passed as a function pointer rather than calling the function immediately

    Correct answer
    D

    The function name can be passed as a function pointer rather than calling the function immediately

    Explanation

    Passing the function name without parentheses supplies its address as a function pointer; the new thread can then begin executing that function.

  54. 54

    What does pthread_self provide?

    1. A

      The number of threads waiting to be joined

    2. B

      The identifier of the process's main function

    3. C

      The calling thread's own identifier

    4. D

      A lock on every shared global variable

    Correct answer
    C

    The calling thread's own identifier

    Explanation

    pthread_self returns the identifier of the thread that calls it.

  55. 55

    Why does the lecture caution that a thread ID may not be a simple human-readable integer?

    1. A

      It may be represented by a structure and requires appropriate methods for comparison

    2. B

      It contains the thread's entire source code

    3. C

      It is always stored as a formatted string on the process stack

    4. D

      It is generated only after the thread has terminated

    Correct answer
    A

    It may be represented by a structure and requires appropriate methods for comparison

    Explanation

    Thread IDs may be represented by a structure rather than a simple integer, so they are not necessarily human-readable and should be compared using suitable functions.

  56. 56

    Which statement correctly describes one way a thread can terminate itself?

    1. A

      It must destroy its own thread ID with pthread_self

    2. B

      It must call pthread_cancel on the process's main thread

    3. C

      It can call pthread_exit to stop its own execution

    4. D

      It can terminate only by making a blocking system call

    Correct answer
    C

    It can call pthread_exit to stop its own execution

    Explanation

    A thread can call pthread_exit to end its own execution.

  57. 57

    What happens if a thread reaches the end of its start routine without being kept in a loop?

    1. A

      The thread becomes a user-level thread

    2. B

      The thread terminates

    3. C

      The thread blocks until another thread calls pthread_self

    4. D

      The thread restarts at the beginning of the process

    Correct answer
    B

    The thread terminates

    Explanation

    A thread terminates if it falls off the end of the routine it was started in.

  58. 58

    Which function is identified as a way for one thread to cancel another thread?

    1. A

      pthread_mutex_unlock

    2. B

      pthread_cancel

    3. C

      pthread_create

    4. D

      pthread_self

    Correct answer
    B

    pthread_cancel

    Explanation

    The lecture identifies pthread_cancel as a way for one thread to terminate another externally.

  59. 59

    What happens to all threads if any thread calls exit?

    1. A

      The entire process ends, so all its threads terminate

    2. B

      All threads continue, but the main thread is restarted

    3. C

      The scheduler converts the remaining threads into processes

    4. D

      Only the thread that called exit terminates

    Correct answer
    A

    The entire process ends, so all its threads terminate

    Explanation

    exit terminates the entire process, which causes all threads in that process to die as well.

  60. 60

    In the sample thread program, what does the perform_work routine do with its argument?

    1. A

      It treats the argument as a mutex and locks it

    2. B

      It treats the argument as a thread ID and destroys that thread

    3. C

      It ignores the argument and returns the process's exit status

    4. D

      It interprets the argument pointer as an integer pointer, obtains the integer, and reports it

    Correct answer
    D

    It interprets the argument pointer as an integer pointer, obtains the integer, and reports it

    Explanation

    The example casts the void pointer to an integer pointer, dereferences it to obtain the passed integer, and prints that value as the thread's argument.

  61. 61

    In the example, why is the thread argument cast to a void* when passed to pthread_create?

    1. A

      The function accepts only a void* because it does not return a value

    2. B

      The cast turns the integer into a thread ID

    3. C

      The function's argument parameter is a void*, so the integer's address is passed using that expected pointer type

    4. D

      The cast makes the thread execute before it is created

    Correct answer
    C

    The function's argument parameter is a void*, so the integer's address is passed using that expected pointer type

    Explanation

    The example passes the address of an integer argument, cast to void*, because the thread start routine receives its argument as a void*.

  62. 62

    What does #define NUM_THREADS 5 accomplish in the example described?

    1. A

      It tells the scheduler to assign five CPU cores

    2. B

      It makes the preprocessor replace occurrences of NUM_THREADS with 5

    3. C

      It creates five threads before the program begins

    4. D

      It stores five as a value returned by each thread

    Correct answer
    B

    It makes the preprocessor replace occurrences of NUM_THREADS with 5

    Explanation

    The preprocessor replaces occurrences of the macro name with its defined value; it does not itself create threads.

  63. 63

    How many thread-creation iterations occur in the sample when the thread count is five?

    1. A

      Five, with indexes from zero through four

    2. B

      Six, with indexes from zero through five

    3. C

      Five, with indexes from one through five

    4. D

      Four, with indexes from zero through three

    Correct answer
    A

    Five, with indexes from zero through four

    Explanation

    The loop runs while the index is less than five, so it creates five threads with indexes zero, one, two, three, and four.

  64. 64

    What is the purpose of pthread_join in the example?

    1. A

      It cancels the specified thread immediately

    2. B

      It locks the specified thread's stack

    3. C

      It creates a new thread using the specified thread's ID

    4. D

      It makes the calling thread wait until the specified thread terminates

    Correct answer
    D

    It makes the calling thread wait until the specified thread terminates

    Explanation

    pthread_join blocks the calling thread until the specified thread has completed.

  65. 65

    Why can thread messages appear in an order different from the order in which threads were created?

    1. A

      The function pointer determines a fixed random order

    2. B

      Thread IDs are always assigned in reverse order

    3. C

      The main thread must wait for each new thread before creating the next

    4. D

      The operating system schedules concurrent threads, so their execution order can vary

    Correct answer
    D

    The operating system schedules concurrent threads, so their execution order can vary

    Explanation

    The operating system determines when each concurrently running thread executes, so output can appear in an order different from creation order.

  66. 66

    In the sample, why can a thread report that it is running before all five threads have been created?

    1. A

      A newly created thread may execute concurrently while the main thread continues creating others

    2. B

      The pthread_create call creates all five threads at once

    3. C

      The loop prints messages for threads that have not been created

    4. D

      The thread's message is produced by the preprocessor

    Correct answer
    A

    A newly created thread may execute concurrently while the main thread continues creating others

    Explanation

    Threads can start executing as they are created, while the main thread continues through the creation loop.

  67. 67

    Why does the sample's main thread observe thread completion in the order of its join loop?

    1. A

      The scheduler forces all threads to finish in numerical order

    2. B

      Threads are required to terminate in the order they were created

    3. C

      It joins the thread IDs in sequence and waits at each join until that thread terminates

    4. D

      The printf function sorts completed thread IDs

    Correct answer
    C

    It joins the thread IDs in sequence and waits at each join until that thread terminates

    Explanation

    The main thread joins the thread IDs in sequence, so it waits for each selected thread before moving to the next, even if the threads themselves finish in another order.

  68. 68

    Why does the lecture describe calling exit at the end of main as poor style when a return is possible?

    1. A

      Returning from main always leaves the program's threads running forever

    2. B

      Returning from main is the normal way to return its status, while exit terminates the process directly

    3. C

      exit cannot provide a status to the operating system

    4. D

      exit can terminate only one thread and cannot end a process

    Correct answer
    B

    Returning from main is the normal way to return its status, while exit terminates the process directly

    Explanation

    The example notes that exit terminates the process where it stands and supplies an exit status, whereas returning from main is preferable when simply finishing the program.

  69. 69

    What does an assert check do in the sample program?

    1. A

      It creates a thread only when the condition is false

    2. B

      It verifies a condition, and program execution stops if that condition is false

    3. C

      It blocks until every thread has terminated

    4. D

      It converts a thread's argument into a return value

    Correct answer
    B

    It verifies a condition, and program execution stops if that condition is false

    Explanation

    The example uses assert to verify that an operation succeeded; if the asserted condition is false, the assertion fails and stops the program.

  70. 70

    What does the term mutex abbreviate?

    1. A

      Mutual exclusion

    2. B

      Multiprocess execution

    3. C

      Memory exchange

    4. D

      Multiple execution

    Correct answer
    A

    Mutual exclusion

    Explanation

    Mutex is an abbreviation for mutual exclusion.

  71. 71

    How does the lecture characterize a mutex in relation to a lock?

    1. A

      It is a variable-based lock that can protect data or resources

    2. B

      It is a thread identifier used to compare two processes

    3. C

      It is a file-based lock that can protect only the operating system

    4. D

      It is a scheduler rule that prevents threads from running

    Correct answer
    A

    It is a variable-based lock that can protect data or resources

    Explanation

    Mutexes are described as variable locks that can provide thread synchronization and protect data or resources.

  72. 72

    What is required for a mutex to protect shared data effectively?

    1. A

      Each thread must create a new mutex before every read

    2. B

      The operating system must replace all global variables with mutexes

    3. C

      The programmer must use it at the appropriate points in the code

    4. D

      The mutex automatically identifies every shared resource and locks it

    Correct answer
    C

    The programmer must use it at the appropriate points in the code

    Explanation

    The lecture emphasizes that mutexes provide locking mechanisms, but the programmer must decide where and how to use them.

  73. 73

    What initializes a statically defined mutex in the example?

    1. A

      PTHREAD_MUTEX_DESTROY

    2. B

      pthread_self

    3. C

      pthread_join

    4. D

      PTHREAD_MUTEX_INITIALIZER

    Correct answer
    D

    PTHREAD_MUTEX_INITIALIZER

    Explanation

    The lecture shows a mutex being initialized with the PTHREAD_MUTEX_INITIALIZER macro.

  74. 74

    Which function ends the lifetime of an initialized mutex in the example?

    1. A

      pthread_mutex_lock

    2. B

      pthread_create

    3. C

      pthread_mutex_destroy

    4. D

      pthread_cancel

    Correct answer
    C

    pthread_mutex_destroy

    Explanation

    The lecture identifies the destroy function as the way to destroy a mutex.

  75. 75

    What happens when a thread calls pthread_mutex_lock on an unlocked mutex?

    1. A

      The calling process is terminated

    2. B

      All other threads acquire the same lock

    3. C

      The mutex is destroyed

    4. D

      The thread acquires the lock

    Correct answer
    D

    The thread acquires the lock

    Explanation

    Calling the lock function acquires the mutex if it is available.

  76. 76

    What happens when a thread attempts to lock a mutex that is already locked?

    1. A

      The mutex is automatically unlocked

    2. B

      The owning thread is immediately cancelled

    3. C

      The thread receives a new mutex identifier and continues

    4. D

      The attempt blocks until the mutex becomes available

    Correct answer
    D

    The attempt blocks until the mutex becomes available

    Explanation

    An attempt to lock an already locked mutex blocks until the mutex is unlocked.

  77. 77

    Who should unlock a mutex after acquiring it, according to the lecture?

    1. A

      The thread that created the process

    2. B

      The thread that previously locked it

    3. C

      Any process, whether or not it acquired the lock

    4. D

      The scheduler after a fixed time interval

    Correct answer
    B

    The thread that previously locked it

    Explanation

    The lecture describes the thread that locked the mutex as calling the unlock function to release it.

  78. 78

    What does pthread_mutex_trylock let a thread do?

    1. A

      Wait indefinitely until every thread has completed

    2. B

      Check whether it can acquire the mutex without blocking

    3. C

      Destroy a mutex only if it has never been used

    4. D

      Unlock a mutex owned by another thread

    Correct answer
    B

    Check whether it can acquire the mutex without blocking

    Explanation

    trylock provides a non-blocking attempt to acquire a mutex and returns a result indicating whether the lock was available.

  79. 79

    Which statement distinguishes a counting semaphore from a binary semaphore?

    1. A

      A counting semaphore blocks all execution, while a binary semaphore never blocks

    2. B

      A counting semaphore has two states, while a binary semaphore tracks any resource quantity

    3. C

      A counting semaphore tracks a quantity of available resources, while a binary semaphore has two states

    4. D

      A counting semaphore is used only by processes, while a binary semaphore is used only by library functions

    Correct answer
    C

    A counting semaphore tracks a quantity of available resources, while a binary semaphore has two states

    Explanation

    A counting semaphore tracks a resource count, such as available buffers or connections; a binary semaphore has only two states, such as locked and unlocked.

  80. 80

    Which is an example of a quantity that a counting semaphore could track?

    1. A

      The order in which source files were compiled

    2. B

      The number of arguments accepted by main

    3. C

      The name of a thread's start routine

    4. D

      The number of available buffers

    Correct answer
    D

    The number of available buffers

    Explanation

    The lecture lists available buffers, open files, and established connections as examples of resource counts tracked by counting semaphores.

  81. 81

    Which description best fits a mutex as a binary semaphore?

    1. A

      It stores the arguments passed to each thread

    2. B

      It tracks an unrestricted number of available CPU cores

    3. C

      It represents two states, such as locked and unlocked

    4. D

      It records how many system calls a process has made

    Correct answer
    C

    It represents two states, such as locked and unlocked

    Explanation

    The lecture describes a binary semaphore as having two states; for a mutex, these are locked and unlocked.

  82. 82

    Who is credited in the lecture with inventing semaphores?

    1. A

      The creators of the UNIX scheduler

    2. B

      Edsger Dijkstra

    3. C

      The developers of the Therac-25

    4. D

      A POSIX standards committee

    Correct answer
    B

    Edsger Dijkstra

    Explanation

    The lecture credits Edsger Dijkstra with inventing semaphores around 1962 or 1963.

Question 1 of 82
Question 1 of 82

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent