Concurrency in Operating Systems
- 82Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Which program design best supports concurrency as described in the lecture?
Which program design best supports concurrency as described in the lecture?
82 questions
- 1
Which program design best supports concurrency as described in the lecture?
- A
Divide the program into order-independent parts that can run without interfering
- B
Divide the program into parts that must finish in a fixed sequence
- C
Combine all operations into one part that waits for every input
- D
Run multiple copies of one instruction stream that share no CPU time
Correct answer
ADivide 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.
- A
- 2
Which statement about processes on UNIX is supported by the lecture?
- A
Multiple processes, including copies of the same program, can run simultaneously
- B
A process must finish before another process can begin running
- C
Processes can run simultaneously only if each has a separate operating system
- D
Only one process can exist for a given program at a time
Correct answer
AMultiple 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.
- A
- 3
How can concurrency improve CPU efficiency when one process is waiting for input or output?
- A
The waiting process automatically becomes a separate CPU core
- B
Another process can use the CPU while the first process waits
- C
The waiting process continues using the CPU while the device responds
- D
The operating system pauses all other processes until the input or output finishes
Correct answer
BAnother 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.
- A
- 4
What does multiprogramming mean in the lecture?
- A
The CPU executes every ready process at exactly the same instant
- B
One process is divided into user-level threads only
- C
More than one process can be ready to execute
- D
More than one process must execute on separate physical CPUs
Correct answer
CMore 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.
- A
- 5
In the lecture's description of multiprogramming, what can prompt a process to hand off control?
- A
The process becomes blocked while waiting for an input/output operation
- B
The process reaches a formatted-print library function
- C
The process creates another copy of its source code
- D
The process receives a new global variable
Correct answer
AThe 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.
- A
- 6
What is a context switch?
- A
Moving a process's data from the heap to its stack
- B
Changing a user-level thread into a separate program
- C
Changing a process's library function into a system call
- D
Changing from one process to another
Correct answer
DChanging from one process to another
Explanation
A context switch is the act of switching execution from one process to another.
- A
- 7
How does timesharing differ from multiprogramming in the lecture?
- A
Timesharing requires multiple physical CPUs, while multiprogramming requires one
- B
Timesharing divides CPU time among processes, while multiprogramming can switch when a process blocks
- C
Timesharing runs only blocked processes, while multiprogramming runs only completed processes
- D
Timesharing applies only to threads, while multiprogramming applies only to library functions
Correct answer
BTimesharing 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.
- A
- 8
What does multiprocessing mean, in contrast to multiprogramming?
- A
Several processes are ready, but only one can ever execute
- B
Several processes are actually executing at the same time
- C
A single process takes turns among its library functions
- D
The operating system schedules only processes that are blocked
Correct answer
BSeveral 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.
- A
- 9
What role can multiple CPU cores play in multiprocessing?
- A
Each core can execute processing from a program, allowing work to run simultaneously
- B
Each core stores a separate copy of the operating system scheduler
- C
Each core prevents its processes from sharing any data
- D
Each core turns a system call into a library function
Correct answer
AEach 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.
- A
- 10
What is the kernel, according to the lecture?
- A
A user-level thread that executes only input and output operations
- B
A file used by processes to signal that a resource is available
- C
A library of application functions that cannot interact with hardware
- D
The central part of the operating system, containing core routines and hardware-abstraction support
Correct answer
DThe 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.
- A
- 11
What is one of the kernel's primary duties described in the lecture?
- A
Preventing processes from making requests for operating-system services
- B
Assigning every process a separate physical CPU
- C
Providing a scheduler to distribute CPU time among processes or threads
- D
Converting all user-level threads into library functions
Correct answer
CProviding 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.
- A
- 12
How does a program typically request that the kernel perform an operation on its behalf?
- A
By creating a user-level thread
- B
By declaring a global variable
- C
By making a system call
- D
By returning from its main function
Correct answer
CBy making a system call
Explanation
A system call is a request made to the kernel to perform an operation on behalf of a process.
- A
- 13
What happens to a process when it makes a system call, as described in the lecture?
- A
The process automatically divides itself into multiple kernel threads
- B
The process continues past the call while the operating system performs it later
- C
The process is converted into a library function and keeps running uninterrupted
- D
Control passes to the operating system, and the process commonly blocks until the call returns
Correct answer
DControl 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.
- A
- 14
Why might a process block while performing a read or write system call?
- A
The operating system cannot perform input or output for processes
- B
The call changes every thread in the process into a separate program
- C
It is waiting for an operation, such as obtaining or writing data, that it cannot carry out by itself
- D
The call requires the process to delete its stack before continuing
Correct answer
CIt 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.
- A
- 15
Which example is presented as a C library function rather than a system call?
- A
Passing control to the operating system for a service
- B
Calculating a square root
- C
Requesting data from a storage device
- D
Writing data to a device
Correct answer
BCalculating 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.
- A
- 16
How does the lecture contrast a C library function with a system call?
- A
A library function can be used only by the kernel, while a system call can be used only by a process
- B
A library function creates a new process, while a system call creates a new global variable
- C
A library function does not make the same operating-system service request that can block a process
- D
A library function always blocks, while a system call never affects process execution
Correct answer
CA 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.
- A
- 17
What determines how the scheduler distributes CPU time, according to the lecture?
- A
The order in which source files were written
- B
Its programmed priorities or fairness policy
- C
Whether a process uses formatted output
- D
The number of global variables in each process
Correct answer
BIts programmed priorities or fairness policy
Explanation
The scheduler distributes prioritized or fair CPU time based on its priorities and how it has been programmed.
- A
- 18
Why can race conditions be difficult to detect during testing?
- A
They may require a rare combination of events and timing to occur
- B
They occur only when a program has no shared resources
- C
They can be detected only by examining source-code formatting
- D
They always produce the same visible failure on every run
Correct answer
AThey 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.
- A
- 19
Which description best captures a race condition as defined in the lecture?
- A
A process that waits until a system call returns
- B
A flaw where a program always produces the same result regardless of event timing
- C
A flaw where the output depends unexpectedly and critically on the relative timing of events
- D
A scheduler policy that gives each process equal CPU time
Correct answer
CA 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.
- A
- 20
In the ATM example, how can two simultaneous withdrawals incorrectly leave an account balance too high?
- A
Each process subtracts from the other's local stack and doubles the account balance
- B
The bank account refuses the first write but accepts both reads
- C
Both processes read the same starting balance, subtract separately, and overwrite one another's update
- D
The operating system converts both withdrawals into deposits
Correct answer
CBoth 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.
- A
- 21
What condition makes the ATM balance example a race condition?
- A
The final balance depends on the timing and ordering of the two processes' reads and writes
- B
Each withdrawal has a fixed amount
- C
The two ATMs are located in different cities
- D
The account balance is stored by the bank
Correct answer
AThe 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.
- A
- 22
What general security risk can arise when concurrent processes share data or resources?
- A
The scheduler may be unable to identify any running process
- B
The processes are forced to use separate operating systems
- C
A process may gain access to sensitive information that should be restricted
- D
Every shared variable is automatically deleted
Correct answer
CA 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.
- A
- 23
What lesson does the Therac-25 example illustrate about safety interlocks?
- A
Hardware interlocks make it impossible for people to enter information too quickly
- B
The system was safe because its errors appeared on a screen
- C
Removing hardware interlocks and relying only on software interlocks can contribute to catastrophic failures
- D
Software interlocks always prevent race conditions without testing
Correct answer
CRemoving 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.
- A
- 24
In the Therac-25 account, what assumption about user behavior contributed to the problem?
- A
The system assumed users would never read messages on the screen
- B
The system relied on users waiting for the machine to shut down between keystrokes
- C
The system relied on users entering information slowly, but users became faster with experience
- D
The system assumed users would enter information only through hardware interlocks
Correct answer
CThe 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.
- A
- 25
When does the lecture say access control is necessary for a concurrent resource?
- A
Only when the resource is a C library function
- B
When multiple processes may access it and at least one may write to it
- C
Whenever two processes exist, even if neither can access shared data
- D
Only when every process reads the resource but none can write
Correct answer
BWhen 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.
- A
- 26
While one process is writing to a shared resource, what access rule does the lecture recommend?
- A
Other processes may access it whenever they use a different CPU core
- B
Other processes may read it but must not write to it
- C
Other processes may write to it but must not read it
- D
No other process should read or write the resource until the write is complete
Correct answer
DNo 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.
- A
- 27
What is the purpose of a lock in the lecture's description of access control?
- A
It ensures the scheduler runs one process forever
- B
It automatically repairs inconsistent data after a race
- C
It allows every process to write to a resource simultaneously
- D
It restricts access to a resource to the process that owns the lock
Correct answer
DIt 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.
- A
- 28
How can a lock-file approach indicate that a resource is already locked?
- A
A process renames its main function to match the resource
- B
A process attempts to create a known lock file and treats its existing presence as another process's lock
- C
A process reads the resource and checks whether its value is zero
- D
A process creates a new CPU core and assigns the resource to it
Correct answer
BA 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.
- A
- 29
What does the sample lock-file loop do after discovering that the lock file already exists?
- A
It terminates every process using the resource
- B
It converts the lock file into a thread identifier
- C
It sleeps briefly and tries again in a later loop iteration
- D
It assumes the resource is unlocked and writes immediately
Correct answer
CIt 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.
- A
- 30
Why can threads communicate more simply than separate processes, as described in the lecture?
- A
Separate processes always share their stacks automatically
- B
Threads in the same process share code, heap memory, and global or static data
- C
Threads each have a separate operating system kernel
- D
Threads never need memory to communicate
Correct answer
BThreads 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.
- A
- 31
Which memory area does each thread have for its own function-call state and automatic variables?
- A
Its own stack
- B
A private copy of all global variables
- C
A separate kernel
- D
A separate copy of the process's entire heap
Correct answer
AIts own stack
Explanation
Each thread has its own stack to track function returns and automatic variables used as it executes.
- A
- 32
What does the lecture say about one thread's ability to access another thread's stack memory?
- A
It can access that memory because the threads share the process's address space
- B
It can access it only after creating a new process
- C
It can never access that memory under any circumstances
- D
It can access it only through a system call that copies the stack
Correct answer
AIt 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.
- A
- 33
Why can switching between threads in one process be faster than switching between processes?
- A
Threads have no execution state to preserve
- B
Threads never require the scheduler to choose what runs
- C
Threads share much of their process's data, so that memory need not be unloaded and loaded again
- D
Threads run only as library functions and cannot be interrupted
Correct answer
CThreads 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.
- A
- 34
How can kernel-level threads provide true concurrent execution on a multicore CPU?
- A
Different threads can be run on separate cores at the same time
- B
Each thread must first become a separate operating system
- C
Each thread is translated into a library function that runs sequentially
- D
The scheduler prevents threads from running at the same time
Correct answer
ADifferent 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.
- A
- 35
What is one disadvantage of threads when they access shared resources without coordination?
- A
The threads are automatically isolated from shared data
- B
The scheduler must assign every thread a separate file
- C
The process can no longer make system calls
- D
Race conditions can occur
Correct answer
DRace conditions can occur
Explanation
Because threads can access shared resources, uncoordinated access can produce race conditions and other problems.
- A
- 36
What resource contention example is given for threads?
- A
A thread's stack prevents every other thread from using the CPU
- B
A library function forces all threads to use different source files
- C
A system call involving a file can block access while another thread is using that file
- D
A global variable prevents the operating system from starting the process
Correct answer
CA 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.
- A
- 37
Why can sharing between threads create a confidentiality concern?
- A
Each thread's private stack is the only memory it can access
- B
Sensitive data available in the shared process may be visible to threads that should not use it
- C
A thread cannot access data created by another thread
- D
Threads automatically encrypt all global variables
Correct answer
BSensitive 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.
- A
- 38
Who controls kernel-level threads and allocates their CPU time?
- A
The C preprocessor
- B
The kernel, through its scheduler
- C
The lock-file naming convention
- D
Only the application through cooperative switching
Correct answer
BThe kernel, through its scheduler
Explanation
Kernel-level threads are controlled by the kernel and receive CPU time through the scheduler.
- A
- 39
What distinguishes user-level threads from kernel-level threads?
- A
User-level threads each have their own kernel scheduler
- B
User-level threads must each run on a separate physical core
- C
The kernel does not know about user-level threads, which are managed inside the process
- D
Kernel-level threads exist only inside C library functions
Correct answer
CThe 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.
- A
- 40
How does switching among user-level threads occur in the lecture's description?
- A
Cooperatively, when the program chooses to switch its line of execution
- B
Only when a thread makes a read system call
- C
Automatically whenever a different CPU core becomes available
- D
Only when the kernel scheduler detects each user-level thread separately
Correct answer
ACooperatively, 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.
- A
- 41
What does the kernel see when a process switches among its user-level threads?
- A
A separate kernel-level thread for every function call
- B
A single running process
- C
A sequence of system calls that must each block
- D
A new operating-system process for every user-level thread
Correct answer
BA 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.
- A
- 42
What is a major disadvantage of user-level threads when a blocking system call occurs?
- A
The system call automatically turns them into independent processes
- B
The operating system must start a new kernel for each thread
- C
The entire process containing them can be blocked
- D
Only the thread that made the call can be unloaded while all others run on separate cores
Correct answer
CThe 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.
- A
- 43
Why can a whole process containing user-level threads be pre-empted?
- A
Each user-level thread always occupies a separate CPU core
- B
User-level threads are system calls that must be completed immediately
- C
A process containing user-level threads has no scheduler
- D
The scheduler sees and schedules the process as a whole, not its internal user-level threads
Correct answer
DThe 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.
- A
- 44
Which statement about user-level threads is consistent with the lecture?
- A
They can switch quickly, but are more difficult to use and are not provided by built-in UNIX libraries in the described way
- B
They cannot be used for a program with multiple lines of execution
- C
They always run on separate cores and cannot be pre-empted
- D
They are controlled by the kernel scheduler and are easier to use than kernel threads
Correct answer
AThey 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.
- A
- 45
What does POSIX provide for UNIX-like systems?
- A
A method for converting all system calls into library functions
- B
A standard way for these systems to interact through common interfaces
- C
A requirement that every process use a separate CPU
- D
A rule that processes must share one global stack
Correct answer
BA 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.
- A
- 46
What is the POSIX threads API used for?
- A
Ensuring all threads run sequentially on one core
- B
Replacing the kernel scheduler with a C preprocessor
- C
Writing multithreaded applications on UNIX-like systems
- D
Creating lock files without using operating-system services
Correct answer
CWriting multithreaded applications on UNIX-like systems
Explanation
The POSIX threads API is described as the standard way to write multithreaded applications on UNIX.
- A
- 47
Which header does the lecture identify for using POSIX thread functions?
- A
stdio.h - B
stdlib.h - C
pthread.h - D
assert.h
Correct answer
Cpthread.hExplanation
The lecture says to include the
pthread.hheader to access the POSIX thread definitions. - A
- 48
What is the purpose of adding the pthread option when compiling with
gcc, as described?- A
To replace the program's
mainfunction with a thread - B
To link in the thread-related functions needed by the program
- C
To convert every library function into a system call
- D
To guarantee that threads complete in creation order
Correct answer
BTo 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.
- A
- 49
What is the first argument to
pthread_createused for?- A
Choosing how the scheduler divides CPU time
- B
Selecting the function that the new thread starts in
- C
Passing the thread's single optional argument
- D
Storing the identifier of the newly created thread
Correct answer
DStoring the identifier of the newly created thread
Explanation
The first
pthread_createargument points to the variable where the new thread's ID is written. - A
- 50
What does the attributes argument to
pthread_createprovide?- A
A pointer to the thread's return value
- B
A pointer to a structure containing thread option flags
- C
The number of other threads that must finish first
- D
The address of the function that created the process
Correct answer
BA 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.
- A
- 51
What does the
start_routineargument topthread_createspecify?- A
The number of arguments the new thread can receive
- B
The function where the new thread begins executing
- C
The function that destroys the entire process
- D
The thread ID that the new thread must use
Correct answer
BThe function where the new thread begins executing
Explanation
The
start_routineis a function pointer identifying where the new thread begins execution. - A
- 52
How can a program pass several values to a thread's start routine when
pthread_createaccepts a single argument pointer?- A
Store every value in the thread ID
- B
Place the values in a structure and pass a pointer to it
- C
Pass each value as a separate
pthread_createargument - D
Use the attributes argument as a list of integers
Correct answer
BPlace the values in a structure and pass a pointer to it
Explanation
The
argparameter is a single argument, so the lecture recommends bundling multiple values into a structure and passing that structure. - A
- 53
Why is a function name passed without parentheses as the
start_routineargument?- A
The parentheses would destroy the thread ID
- B
The function must be called by the scheduler before the thread is created
- C
The function name is being passed as a C preprocessor constant
- D
The function name can be passed as a function pointer rather than calling the function immediately
Correct answer
DThe 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.
- A
- 54
What does
pthread_selfprovide?- A
The number of threads waiting to be joined
- B
The identifier of the process's main function
- C
The calling thread's own identifier
- D
A lock on every shared global variable
Correct answer
CThe calling thread's own identifier
Explanation
pthread_selfreturns the identifier of the thread that calls it. - A
- 55
Why does the lecture caution that a thread ID may not be a simple human-readable integer?
- A
It may be represented by a structure and requires appropriate methods for comparison
- B
It contains the thread's entire source code
- C
It is always stored as a formatted string on the process stack
- D
It is generated only after the thread has terminated
Correct answer
AIt 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.
- A
- 56
Which statement correctly describes one way a thread can terminate itself?
- A
It must destroy its own thread ID with
pthread_self - B
It must call
pthread_cancelon the process's main thread - C
It can call
pthread_exitto stop its own execution - D
It can terminate only by making a blocking system call
Correct answer
CIt can call
pthread_exitto stop its own executionExplanation
A thread can call
pthread_exitto end its own execution. - A
- 57
What happens if a thread reaches the end of its start routine without being kept in a loop?
- A
The thread becomes a user-level thread
- B
The thread terminates
- C
The thread blocks until another thread calls
pthread_self - D
The thread restarts at the beginning of the process
Correct answer
BThe thread terminates
Explanation
A thread terminates if it falls off the end of the routine it was started in.
- A
- 58
Which function is identified as a way for one thread to cancel another thread?
- A
pthread_mutex_unlock - B
pthread_cancel - C
pthread_create - D
pthread_self
Correct answer
Bpthread_cancelExplanation
The lecture identifies
pthread_cancelas a way for one thread to terminate another externally. - A
- 59
What happens to all threads if any thread calls
exit?- A
The entire process ends, so all its threads terminate
- B
All threads continue, but the main thread is restarted
- C
The scheduler converts the remaining threads into processes
- D
Only the thread that called
exitterminates
Correct answer
AThe entire process ends, so all its threads terminate
Explanation
exitterminates the entire process, which causes all threads in that process to die as well. - A
- 60
In the sample thread program, what does the
perform_workroutine do with its argument?- A
It treats the argument as a mutex and locks it
- B
It treats the argument as a thread ID and destroys that thread
- C
It ignores the argument and returns the process's exit status
- D
It interprets the argument pointer as an integer pointer, obtains the integer, and reports it
Correct answer
DIt interprets the argument pointer as an integer pointer, obtains the integer, and reports it
Explanation
The example casts the
voidpointer to an integer pointer, dereferences it to obtain the passed integer, and prints that value as the thread's argument. - A
- 61
In the example, why is the thread argument cast to a
void*when passed topthread_create?- A
The function accepts only a
void*because it does not return a value - B
The cast turns the integer into a thread ID
- C
The function's argument parameter is a
void*, so the integer's address is passed using that expected pointer type - D
The cast makes the thread execute before it is created
Correct answer
CThe function's argument parameter is a
void*, so the integer's address is passed using that expected pointer typeExplanation
The example passes the address of an integer argument, cast to
void*, because the thread start routine receives its argument as avoid*. - A
- 62
What does
#define NUM_THREADS 5accomplish in the example described?- A
It tells the scheduler to assign five CPU cores
- B
It makes the preprocessor replace occurrences of
NUM_THREADSwith5 - C
It creates five threads before the program begins
- D
It stores five as a value returned by each thread
Correct answer
BIt makes the preprocessor replace occurrences of
NUM_THREADSwith5Explanation
The preprocessor replaces occurrences of the macro name with its defined value; it does not itself create threads.
- A
- 63
How many thread-creation iterations occur in the sample when the thread count is five?
- A
Five, with indexes from zero through four
- B
Six, with indexes from zero through five
- C
Five, with indexes from one through five
- D
Four, with indexes from zero through three
Correct answer
AFive, 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.
- A
- 64
What is the purpose of
pthread_joinin the example?- A
It cancels the specified thread immediately
- B
It locks the specified thread's stack
- C
It creates a new thread using the specified thread's ID
- D
It makes the calling thread wait until the specified thread terminates
Correct answer
DIt makes the calling thread wait until the specified thread terminates
Explanation
pthread_joinblocks the calling thread until the specified thread has completed. - A
- 65
Why can thread messages appear in an order different from the order in which threads were created?
- A
The function pointer determines a fixed random order
- B
Thread IDs are always assigned in reverse order
- C
The main thread must wait for each new thread before creating the next
- D
The operating system schedules concurrent threads, so their execution order can vary
Correct answer
DThe 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.
- A
- 66
In the sample, why can a thread report that it is running before all five threads have been created?
- A
A newly created thread may execute concurrently while the main thread continues creating others
- B
The
pthread_createcall creates all five threads at once - C
The loop prints messages for threads that have not been created
- D
The thread's message is produced by the preprocessor
Correct answer
AA 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.
- A
- 67
Why does the sample's main thread observe thread completion in the order of its join loop?
- A
The scheduler forces all threads to finish in numerical order
- B
Threads are required to terminate in the order they were created
- C
It joins the thread IDs in sequence and waits at each join until that thread terminates
- D
The
printffunction sorts completed thread IDs
Correct answer
CIt 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.
- A
- 68
Why does the lecture describe calling
exitat the end ofmainas poor style when a return is possible?- A
Returning from
mainalways leaves the program's threads running forever - B
Returning from
mainis the normal way to return its status, whileexitterminates the process directly - C
exitcannot provide a status to the operating system - D
exitcan terminate only one thread and cannot end a process
Correct answer
BReturning from
mainis the normal way to return its status, whileexitterminates the process directlyExplanation
The example notes that
exitterminates the process where it stands and supplies an exit status, whereas returning frommainis preferable when simply finishing the program. - A
- 69
What does an
assertcheck do in the sample program?- A
It creates a thread only when the condition is false
- B
It verifies a condition, and program execution stops if that condition is false
- C
It blocks until every thread has terminated
- D
It converts a thread's argument into a return value
Correct answer
BIt verifies a condition, and program execution stops if that condition is false
Explanation
The example uses
assertto verify that an operation succeeded; if the asserted condition is false, the assertion fails and stops the program. - A
- 70
What does the term mutex abbreviate?
- A
Mutual exclusion
- B
Multiprocess execution
- C
Memory exchange
- D
Multiple execution
Correct answer
AMutual exclusion
Explanation
Mutex is an abbreviation for mutual exclusion.
- A
- 71
How does the lecture characterize a mutex in relation to a lock?
- A
It is a variable-based lock that can protect data or resources
- B
It is a thread identifier used to compare two processes
- C
It is a file-based lock that can protect only the operating system
- D
It is a scheduler rule that prevents threads from running
Correct answer
AIt 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.
- A
- 72
What is required for a mutex to protect shared data effectively?
- A
Each thread must create a new mutex before every read
- B
The operating system must replace all global variables with mutexes
- C
The programmer must use it at the appropriate points in the code
- D
The mutex automatically identifies every shared resource and locks it
Correct answer
CThe 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.
- A
- 73
What initializes a statically defined mutex in the example?
- A
PTHREAD_MUTEX_DESTROY - B
pthread_self - C
pthread_join - D
PTHREAD_MUTEX_INITIALIZER
Correct answer
DPTHREAD_MUTEX_INITIALIZERExplanation
The lecture shows a mutex being initialized with the
PTHREAD_MUTEX_INITIALIZERmacro. - A
- 74
Which function ends the lifetime of an initialized mutex in the example?
- A
pthread_mutex_lock - B
pthread_create - C
pthread_mutex_destroy - D
pthread_cancel
Correct answer
Cpthread_mutex_destroyExplanation
The lecture identifies the destroy function as the way to destroy a mutex.
- A
- 75
What happens when a thread calls
pthread_mutex_lockon an unlocked mutex?- A
The calling process is terminated
- B
All other threads acquire the same lock
- C
The mutex is destroyed
- D
The thread acquires the lock
Correct answer
DThe thread acquires the lock
Explanation
Calling the lock function acquires the mutex if it is available.
- A
- 76
What happens when a thread attempts to lock a mutex that is already locked?
- A
The mutex is automatically unlocked
- B
The owning thread is immediately cancelled
- C
The thread receives a new mutex identifier and continues
- D
The attempt blocks until the mutex becomes available
Correct answer
DThe attempt blocks until the mutex becomes available
Explanation
An attempt to lock an already locked mutex blocks until the mutex is unlocked.
- A
- 77
Who should unlock a mutex after acquiring it, according to the lecture?
- A
The thread that created the process
- B
The thread that previously locked it
- C
Any process, whether or not it acquired the lock
- D
The scheduler after a fixed time interval
Correct answer
BThe thread that previously locked it
Explanation
The lecture describes the thread that locked the mutex as calling the unlock function to release it.
- A
- 78
What does
pthread_mutex_trylocklet a thread do?- A
Wait indefinitely until every thread has completed
- B
Check whether it can acquire the mutex without blocking
- C
Destroy a mutex only if it has never been used
- D
Unlock a mutex owned by another thread
Correct answer
BCheck whether it can acquire the mutex without blocking
Explanation
trylockprovides a non-blocking attempt to acquire a mutex and returns a result indicating whether the lock was available. - A
- 79
Which statement distinguishes a counting semaphore from a binary semaphore?
- A
A counting semaphore blocks all execution, while a binary semaphore never blocks
- B
A counting semaphore has two states, while a binary semaphore tracks any resource quantity
- C
A counting semaphore tracks a quantity of available resources, while a binary semaphore has two states
- D
A counting semaphore is used only by processes, while a binary semaphore is used only by library functions
Correct answer
CA 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.
- A
- 80
Which is an example of a quantity that a counting semaphore could track?
- A
The order in which source files were compiled
- B
The number of arguments accepted by
main - C
The name of a thread's start routine
- D
The number of available buffers
Correct answer
DThe number of available buffers
Explanation
The lecture lists available buffers, open files, and established connections as examples of resource counts tracked by counting semaphores.
- A
- 81
Which description best fits a mutex as a binary semaphore?
- A
It stores the arguments passed to each thread
- B
It tracks an unrestricted number of available CPU cores
- C
It represents two states, such as locked and unlocked
- D
It records how many system calls a process has made
Correct answer
CIt 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.
- A
- 82
Who is credited in the lecture with inventing semaphores?
- A
The creators of the UNIX scheduler
- B
Edsger Dijkstra
- C
The developers of the Therac-25
- D
A POSIX standards committee
Correct answer
BEdsger Dijkstra
Explanation
The lecture credits Edsger Dijkstra with inventing semaphores around 1962 or 1963.
- A

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