Chapter 13 - Concurrency Flashcards
what are the 4 different levels of concurrency
machine instruction level
statement level
unit level
program level
what is machine instruction level concurrency
executing two more machine instructions concurrently
what is statement level concurrency?
executing two or more high-level language statements simultaneously
what is unit level concurrency?
executing two or more subprogram units simultaneously
6 motivations for concurrency
- speed up execution
- increase program flexibility
- resource management in OS
- task management in OS
- solving large-scale problems
- simulates actual physical systems that consist of multiple concurrent subsystems
what is a scalable concurrent algorithm?
an algorithm with which the speed of execution increases when more processors are available
what is a thread of control?
a sequence of program points reached as control flows through the program
what is physical concurrency?
multiple independent processors (multiple threads of control)
what is logical concurrency?
the appearance of physical concurrency is presented by time-sharing one processor
what is hidden concurrency and what are 3 kinds of it?
- concurrency that is built into processor architectures
- pipelining of instruction (run instruction A, while preparing instruction B, while fetching instruction C)
- separate lines (buses) for instructions and data
- prefetching of instruction and data
3 differences between a task (aka a process) and a subprogram
Tasks are:
- implicitly started
- invoking unit need not wait for the task to finish to resume itself
- upon completion of the task, control may or may not return to the invoker
what is a lightweight vs a heavyweight task?
lightweight tasks all run in a single address space and heavyweight tasks each run in their own address space
what is a program “guard”
a linguistic device that allows the guarded code to be executed only when a specified condition is true
what is a task descriptor?
-a data structure that stores all of the relevant information about the execution state of a task
what is cooperation synchronization
when two processes must perform their work in some mandated order
what competition synchronization
when two processes need to access some resource but must not do it at the same time
what is the Ada “accept” statement (3 things)
-its represents the entry point for a task using “Rendevous” for synchronization
each accept statement has an associated process queue
-the “server” waits when the accept statement is reached until a process meets the “when” statement requirements and is in one of its process queues
rendezvous actor task vs server task
server task - a task with accept clauses
actor task - a task without accept clauses
what is the Rendevous “pragma” keyword?
-assigns priority to tasks in the specification
what is the Java “synchronized” keyword
when applied to methods within an object it disallows those methods from being run concurrently on different threads
when to applied to set of statements then those statements cannot be run concurrently by different threads
4 java thread class methods
start- call the run method implemented in whatever runnable object
yield- a hint to the scheduler that the current thread is willing to yield its current use of the processor if needed. Moves thread to ready state
sleep- moves the thread into the blocked state
join- forces a method to delay its execution until the run method of another thread has completed its execution
What is the equivalent of P and V for Java semaphores?
s = new Semaphore(0) --> constructor with initial value of zero f = new Semaphore(MAX)
s.acquire() //same as P
[blah, blah, blah]
f.release() //same as V
2 ways to define a Java class with run() for threads
- create a class that extends the Thread class and override run (only if the class has no parents)
- create a that implements Runnable interface and define the functionality of run()
what is the Java “notifyAll” method?
-it tells all other threads that some event that a thread may have been waiting for has possibly occurred
what are atomic Integer, Boolean, and Long types?
-they are just like Integer, Boolean, and Long classes but their operations are non-interruptible