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

  • 83Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Concurrency Concepts
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What does concurrency mean in programming?

Tap to flipClick to flipspace

Doing multiple things at the same time, or organizing work so multiple parts can run without interfering.

Or swipe the card

83 cards

  1. What does concurrency mean in programming?

    Doing multiple things at the same time, or organizing work so multiple parts can run without interfering.

  2. What makes parts of a program suitable for concurrent execution?

    They can run at the same time without interfering with one another; their execution order is not important.

  3. How can UNIX run multiple processes, including multiple copies of one program?

    The operating system can run multiple processes and share CPU time among them.

  4. How can concurrency improve CPU efficiency when a process is waiting for input or output?

    The CPU can run another process while the waiting process is blocked.

  5. What is a system call?

    A request by a process for an operating-system service that transfers control to the operating system.

  6. What typically happens to a process while it waits for a system call to return?

    It blocks: it is stalled at the call and cannot continue until the call returns.

  7. How does a C library function differ from a system call?

    A library function performs a program-level operation, such as calculating a square root or formatting output; it does not itself request an operating-system service or block in the way described for system calls.

  8. What is multiprogramming?

    An arrangement in which more than one process can be ready to execute, with processes handing off control when they cannot proceed.

  9. What is a context switch?

    Switching execution from one process to another.

  10. What is timesharing?

    Dividing CPU time among multiple processes so they appear to run at the same time.

  11. How do multiprogramming and timesharing differ?

    Multiprogramming lets a process hand off control when it cannot proceed, such as while blocked; timesharing divides CPU time among processes regardless of what they are doing.

  12. What is multiprocessing?

    Executing multiple processes at the same time, typically by using multiple CPU cores.

  13. What is a race condition?

    A flaw in which the output depends unexpectedly and critically on the relative timing of events.

  14. How can concurrent access to shared data create a race condition?

    Two processes may read or update the same resource at overlapping times, causing the result to depend on the order in which their operations occur.

  15. How can two simultaneous ATM withdrawals cause a lost update?

    Both processes may read the same balance, subtract the withdrawal separately, and write back competing results, so one subtraction is lost.

  16. Why can race conditions be difficult to detect?

    They may require a rare, specific timing or set of circumstances to occur, so testing may not expose them.

  17. What happened in the Therac-25 software disaster described in the lecture?

    A radiation therapy machine's software interlocks failed to prevent dangerous operation; three people died and three others were seriously injured.

  18. What safety lesson does the Therac-25 example illustrate?

    Systems that control dangerous equipment need reliable safeguards and access control; software-only checks can fail in timing-sensitive situations.

  19. When should a shared resource be protected with access control?

    When multiple processes may access a resource concurrently and at least one may write to it.

  20. What access rule should apply while a process is writing to a shared resource?

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

  21. What is the purpose of a lock on a shared resource?

    To ensure that only the process holding the lock can access the resource while it is protected.

  22. How can a lock file provide access control?

    A process attempts to create a known lock-file path; successful creation indicates it acquired the lock, while an existing file indicates another process has it.

  23. What is the kernel of an operating system?

    The central part of the operating system, containing fundamental routines and hardware-abstraction mechanisms that communicate with hardware through drivers.

  24. What is one of the kernel's primary duties?

    Providing the scheduler, which distributes CPU time among processes or threads.

  25. How does a process request that the kernel perform an operation?

    It makes a system call.

  26. What is a thread?

    A line of execution within a process, organized to perform a particular sequence of work.

  27. How could a chat server use threads to handle concurrent work?

    It could use separate threads for tasks such as monitoring user connections, receiving messages, and sending output.

  28. Which parts of a program's memory do its threads share?

    They share the program code, heap, global variables, and static data.

  29. What memory does each thread have separately?

    Each thread has its own stack for function return information and automatic variables.

  30. Why can switching between threads be faster than switching between processes?

    Threads in the same process share much of their program state, so less data needs to be unloaded and reloaded during a switch.

  31. How can threads achieve true simultaneous execution on a multicore CPU?

    Kernel-level threads can be scheduled on separate CPU cores and run at the same time.

  32. What are three risks or disadvantages of threads?

    Race conditions, contention for resources, and exposure of shared sensitive data.

  33. How can threads create resource contention?

    Two threads may attempt to use the same resource, such as a file, at the same time; one may have to wait.

  34. What is a kernel-level thread?

    A thread managed by the kernel and given CPU time by the scheduler.

  35. What is a user-level thread?

    A thread managed within a process without the kernel directly knowing about it.

  36. How is switching between user-level threads typically controlled?

    Cooperatively by the program, which chooses when to switch between its lines of execution.

  37. Why can user-level thread switching be faster than kernel-thread switching?

    The program can switch between its own execution paths without performing a kernel-managed thread switch.

  38. What is a major disadvantage of user-level threads when the scheduler preempts their process?

    The entire process containing the threads can be preempted or unloaded, rather than just one user-level thread.

  39. What happens if a user-level-thread process makes a blocking system call?

    The entire process can block, including all of its user-level threads.

  40. What are user-level threads sometimes called, and why?

    They are sometimes called green threads because they do not occupy kernel scheduling time as separate threads.

  41. What is a practical advantage of kernel-level threads over user-level threads?

    They are managed by the kernel, can be scheduled independently, and are supported by standard UNIX libraries.

  42. What is POSIX, and why is it relevant to UNIX threads?

    POSIX is a standard for interfaces shared by UNIX-like operating systems; its thread API is a standard way to write multithreaded UNIX applications.

  43. Which header provides the POSIX thread declarations described in the lecture?

    pthread.h.

  44. What compiler option is needed to link a program using POSIX threads with GCC?

    Use the -pthread option when compiling and linking.

  45. What does pthread_create do?

    It creates a new thread that begins execution at a specified start routine.

  46. What are the four arguments to pthread_create?

    A pointer to the new thread's ID, a pointer to thread attributes, a start-routine function pointer, and an argument to pass to that routine.

  47. What is the purpose of the first argument to pthread_create?

    It identifies where the new thread's ID should be stored.

  48. What does the attributes argument to pthread_create specify?

    Optional thread settings, provided through an attributes structure.

  49. What is the start-routine argument to pthread_create?

    A function pointer specifying where the new thread begins execution.

  50. How does the argument passed to a pthread_create start routine work?

    A single argument is passed to the routine; to pass multiple values, package them in a structure.

  51. Why can a function name be passed to pthread_create without parentheses?

    The function name can be used as a function pointer, identifying the routine rather than calling it immediately.

  52. What is the purpose of pthread_self?

    It returns the ID of the thread that calls it.

  53. How can a program compare two POSIX thread IDs?

    Use the thread-ID comparison functions rather than assuming IDs are ordinary printable integers.

  54. What are common ways a thread can terminate?

    It can call pthread_exit, return from the end of its start routine, be canceled by another thread, or end when any thread calls exit and terminates the process.

  55. What does pthread_exit do?

    It lets the calling thread terminate itself.

  56. What happens when a thread reaches the end of its start routine?

    The thread terminates.

  57. How can one thread terminate another thread?

    It can request cancellation using pthread_cancel.

  58. What is the effect of calling exit from any thread in a process?

    It terminates the entire process, so all of the process's threads end.

  59. What does pthread_join do?

    It blocks the calling thread until the specified target thread terminates.

  60. Why does a main thread often call pthread_join on worker threads?

    To wait until the workers have completed before continuing or reporting that all work is done.

  61. How can the order of pthread_join calls affect the order in which completion messages appear?

    If the main thread joins thread IDs in sequence, it waits for them in that sequence, so its completion messages follow that join order.

  62. In the five-thread example, what range of argument values is passed to the worker threads?

    The threads receive the values 000 through 444, one per thread.

  63. What does the five-thread example's worker routine do?

    It interprets its void * argument as a pointer to an integer, prints a message containing that integer, and returns the value.

  64. Why does the example cast a worker argument to int * and dereference it?

    The argument arrives as a void *, so the routine casts it to an integer pointer and dereferences it to read the integer value.

  65. What does assert do in the thread-creation example?

    It checks that an expected condition is true; if not, the program stops.

  66. Why can messages from thread creation and worker execution appear interleaved?

    The threads run concurrently, and the operating system determines when each gets execution time.

  67. Why is returning from main generally preferable to calling exit at the end of a program?

    Returning from main is the normal way to provide the program's result to the operating system; exit terminates the process abruptly.

  68. What is a mutex?

    A mutual-exclusion lock used to synchronize threads and protect shared data or resources.

  69. How does a mutex differ from the lock-file approach?

    A mutex is a variable-based lock, commonly used to coordinate threads; a lock file uses a file's existence to coordinate access.

  70. How is a POSIX mutex declared and initialized in the lecture's example?

    Declare it as a pthread_mutex_t and initialize it with PTHREAD_MUTEX_INITIALIZER.

  71. How does a thread acquire a mutex?

    It calls pthread_mutex_lock on the mutex.

  72. What happens when a thread tries to lock a mutex that is already locked?

    The attempting thread blocks until the mutex becomes available.

  73. How does a thread release a mutex?

    The thread holding it calls pthread_mutex_unlock.

  74. What happens to waiting threads when a mutex is unlocked?

    A waiting thread is allowed to proceed after acquiring the now-available mutex; the lecture describes the choice among waiters as nondeterministic.

  75. What does pthread_mutex_trylock do?

    It attempts to lock a mutex without blocking and reports whether the lock was available.

  76. How is a mutex destroyed?

    Call the mutex-destroy function when the mutex is no longer needed.

  77. What does it mean that a mutex is a synchronization tool rather than automatic protection?

    Programmers must place lock and unlock operations around the shared data or resource that needs protection.

  78. What is a semaphore?

    A synchronization mechanism that tracks access to resources; it can be viewed as a flag or resource counter.

  79. What is a counting semaphore used to represent?

    The number of available instances of a resource, such as buffers, open files, or connections.

  80. What is a binary semaphore?

    A semaphore with two possible states.

  81. How is a mutex related to semaphores?

    A mutex is a specific form of semaphore, corresponding to a binary locked-or-unlocked state.

  82. Who introduced the concept of semaphores, and approximately when?

    Edsger Dijkstra introduced them around 196219621962 or 196319631963.

  83. What does the five-thread example illustrate about thread scheduling?

    Thread execution and output can interleave in an order determined by the operating system, while joins can make the main thread wait for completion.

Card 1 of 83
Card 1 of 83

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent