質問                    | 
                
                    答え                    | 
            
        
        | 
     学び始める
 | 
 | 
      Concurrency: the existence of multiple simultaneously active execution contexts.   
 | 
 | 
 | 
      what levels can Concurrency    学び始める
 | 
 | 
      Machine instruction level, Statement level, Subprogram level, Program level   
 | 
 | 
 | 
      what is multitasking, in relation to concurrency    学び始める
 | 
 | 
      When concurrency exists between multiple programs on a single computer, we call it multitasking. e.g., the way of most OSs controls multiple tasks.   
 | 
 | 
 | 
      what is multi threading, in relation to concurrency    学び始める
 | 
 | 
      When a program implements concurrency on a single computer, we called the program concurrent/parallel program. Such a program is said to be multithreaded   
 | 
 | 
 | 
      what is distributed program, in relation to concurrency    学び始める
 | 
 | 
      When a program implements concurrency on multiple computers, we called it a distributed program – a program of which different pieces are on computers connected by a network.   
 | 
 | 
 | 
      describe task, process or thread    学び始める
 | 
 | 
      A task, process or thread of a program is a program unit that can be in concurrent execution with other program units.   
 | 
 | 
 | 
      how does A task/processes/thread differs from ordinary subprograms    学び始める
 | 
 | 
      [1] A process/task may be implicitly started. [2] When a multithreaded program starts the execution of a thread, the rest of the program is not necessarily suspended. [3] When a thread’s execution is completed, control may not return to the caller.   
 | 
 | 
 | 
      When is a task considers disjoint    学び始める
 | 
 | 
      A task/thread is disjoint if it does not communicate with (or affect the execution of) any other tasks in the program in any way, otherwise it is a joint task and needs to be synchronised.   
 | 
 | 
 | 
      what must be done with joint tasks?    学び始める
 | 
 | 
      they must be synchronised   
 | 
 | 
 | 
      why is Inter-thread communication necessary for joint tasks    学び始める
 | 
 | 
      [1] exclusive access to some resource, [2] to exchange data with another thread.   
 | 
 | 
 | 
      what are the problems with synchronised joint tasks?    学び始める
 | 
 | 
      If not synchronised, joint tasks can lead to race conditions and deadlocks.   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      A race condition occurs when the resulting value of a variable depends on the execution order of two or more threads.   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      A deadlock is a situation in which two or more competing threads are each waiting for the other to finish while holding resources that the other needs, and thus neither ever does.   
 | 
 | 
 | 
      what 4 conditions must ALL be true for a deadlock    学び始める
 | 
 | 
      Mutual exclusion, Hold and wait, No preemptionl, Circular wait   
 | 
 | 
 | 
      Describe Mutual exclusion    学び始める
 | 
 | 
      Mutual exclusion: Resources may be used only under mutual exclusion – only one process can use the resource at any time.   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      Hold and wait: A process is allowed to hold resources while waiting for others which are being held by other processes.   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      No preemption: Resources cannot be forcibly removed once it is granted to a process.   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      Circular wait: A circular chain of threads exists in which each thread holds a resource needed by the next thread in the chain.   
 | 
 | 
 | 
      Synchronisation requires communication among the tasks, which can be provided by?    学び始める
 | 
 | 
      [1] shared nonlocal variables, [2] message passing, or [3] special data types – semaphores & monitors   
 | 
 | 
 | 
      what is the producer-consumer problem    学び始める
 | 
 | 
      one task produces something that the other task has to consume.   
 | 
 | 
 | 
      describe Cooperation Synchronization    学び始める
 | 
 | 
      Two (or more) tasks have to work in a cooperative way: [1] the second task must wait for the first task to finish execution before it may proceed. [2] Usually, there are more than one unit of resources to be shared.   
 | 
 | 
 | 
      explain how a shared buffer contributes to Cooperation Synchronization    学び始める
 | 
 | 
      [1] Both must use buffer exciv'ly at any 1 time but in a cop'ative way[2] the read thread A needs the buffer to be "not empty" state before it can read. If buffer empty must wait. [3] the write thread B writes the buffer if it is not full. else must wait   
 | 
 | 
 | 
      describe Competition Synchronization    学び始める
 | 
 | 
      Competition synchronisation between tasks is required when both tasks require the use of the same, single unit, resource that must not be simultaneously used   
 | 
 | 
 | 
      give an example of a Competition Synchronization    学び始める
 | 
 | 
      E.g., a shared counter, a bank account, etc., where simultaneously access to the same resources, e.g., amount of credit, should never happen.   
 | 
 | 
 | 
      what is a semeohore used for    学び始める
 | 
 | 
      Semaphores can be used to implement both cooperation and competition synchronizations   
 | 
 | 
 | 
| 
     学び始める
 | 
 | 
      Monitors wrap the resources with the mechanism for exclusive access control and implement competition synchronization.   
 | 
 | 
 | 
      what are the components of a Semaphore    学び始める
 | 
 | 
      [1] a counter to track units of avai'le res's [2] a queue for storing the processes that req't access to the res's [3]2 operations, wait (or P) and signal (or release, or V).   
 | 
 | 
 | 
      what is the purpose of the operations of a semapore    学び始める
 | 
 | 
      two operations, wait (or P) and signal (or release, or V). The processes have to access the shared resources through these two operation – calling wait to request access and calling signal to release.   
 | 
 | 
 | 
      What happens when a process needs access to the resources guarded with a semaphore when it calls the wait() method.    学び始める
 | 
 | 
      [1] the method decrements the value of counter 1 [2] if count val >=0, access to the res granted to the calling process & it on the ready list [3] if coun val<0 the calling process/thread is added to the semaphore's waiting queue the thread is blocked   
 | 
 | 
 | 
      when is the signal() method called    学び始める
 | 
 | 
      When a process finishes the use of the resources, it must relinquish the resources by calling the signal() method.   
 | 
 | 
 | 
      What does the signal() method do    学び始める
 | 
 | 
      [1] increments the value of semaphore counter by 1. [2] if the counter value equals or less than zero (meaning there are threads on waiting queue), transfers a blocked thread from the semaphore's waiting queue to the ready list.   
 | 
 | 
 |