PVW SKRIPT Flashcards
1) Define Parallel Programming.
2) Use example of summing up an array
1) Parallel programming is about using additional computational resources to solve a problem faster.
2) There is no sequential algorithm that can do better than O(n)
Suppose we had 4 processors, we could produce the result 4 times faster by partitioning the array into 4 segments, having each processor sum one segment and combining the results with an extra 3 additions.
Define concurrent programming.
Concurrent Programming is about correctly and efficiently controlling access by multiple threads to shared resources.
Define the programming model used in this lecture with key points use the following:
- threads
- shared memory
We assume:
- explicit threads with shared memory
- two or more threads can communicate by writing and reading fields of the same object
- a thread is like a running sequential programm that can create other threads
- threads can see the same object because we assume memory is shared
What is scheduling?
There may be more threads than processors, than its up to the Java implementation, with help from the underlying operating system, to find a way to let the threads take turns, this is called scheduling.
Why are multithreaded programs harder to test and debug?
Because the are nondeterministic. Rerunning the same multithreaded programm, can give different results.
What are the different thread states in Java?
Non-Existing New Runnable Blocked Waiting Terminated
Define the Non-Existing state.
Non-Existing: Thread hasn’t been created yet
Define the New state.
New: Once a Thread object is created, it enters new state
Define the Runnable state.
Runnable: Once we call start() on the new thread object, it becomes eligible for execution and the system can start scheduling the thread as it wishes.
Define the Blocked state.
Blocked: When a thread attempts to acquire a lock it goes into a blocked state until it has obtained the lock, upon which it returns to a runnable state. In addition, calling the join() method will also transfer a thread into a blocked state.
Define the Waiting state.
Waiting: The thread can call wait() to go into a wating state. It will return to a runnable state once another thread calls notify() or notifyAll() and the thread is removed from the waiting queue.
Define the Terminated state.
Treminated: We can use interrupt() to signal the thread to stop its execution, it will then transfer to a terminated state. Also exiting the run() method is equicvalent to entering a terminated state.
What is a race condition?
A racecondition is a mistake in your program such that whether the program behaves correctly or not depends on the order in which the threads execute.
Race conditions are very common bugs in concurrent programming that, by definition, do not exist in sequential programming.
What are the two types of race conditions?
Bad Interleaving
Data Race
Define the race condition bad interleaving.
(High Level Race Condition) Erroneous programm behavior caused by an unfavorable execution order of a multithreaded algorithm