Fundamentals Flashcards
Define what is meant by the term ATOMIC ACTION (in the context of the concurrent execution of a program)
- A programming instruction which changes the stage of a system indivisibly (i.e it can’t be interrupted by an instruction from another process)
Define what is meant by the term FINITE PROGRESS ASSUMPTION (in the context of the concurrent execution of a program)
- Assume that we can’t tell how fast the sequential components execute
- If more than one process/thread can proceed then we must consider all the possibilities.
- Non-determinism about which actual history of atomic actions will be executed.
Define what is meant by the term INTERLEAVINGS (in the context of the concurrent execution of a program)
- An interleaving of a concurrent program is a list of the atomic actions of its sequential programs.
- Within it, each sequential program is listed in the correct order, but the actions of different sequential components can be intermixed
Define what is meant by the term HISTORIES (in the context of the concurrent execution of a program)
- A history of a concurrent program is a possible interleaving of its atomic actions. Different possible actions when the program is run due to different interleavings.
In Java, a thread can be in one of FOUR STATES. Specify and describe the NEW state.
Thread can be in one of four states;
NEW - occurs when a thread is created but not yet running
Describe two approaches to creating threads in Java, illustrating your answer with example Java programs. When would you use each approach?
Method 1 - create a new subclass of the THREAD class and OVERRIDE the run() method
class SimpleThread extends Thread { public void run() { for (int count = 0; count + Thread.currenthread().getName()); } }//run }//SimpleThread
Consider a main program that instantiates a runnable object (i.e notAThread) and passes it as a parameter to the constructor of Thread. The thread object (i.e parallel) can now be started.
Using examples to illustrate your answer, briefly explain what is meant by a concurrent system.
A concurrent system is one where several components are working at any time, and where useful work is going on in more than one place.
For example, if we consider an example in the form of a program called “Porter” - a concurrent system could utilise two of said porters working simultaneously, working to the benefit of the “processing” speed, but creating the possibility that they may interfere with one another.
Explain the use of threads in a concurrent system.
A thread essentially looks much like a process, and we can consider it as such.
A program can consist of multiple threads (running in a JVM - Java Virtual Machine)
- Essentially, threads allow multiple tasks to be executed
- they allow a single program multiple threads/paths of control.
Benefit of using threads - PROGRAM STRUCTURE
Sometimes, complex programs can be more clearly modeled using multiple threads, plus this makes them easier to understand and debug.
Benefit of using threads - SYSTEM RESOURCES
Whereas multiple processes typically means more resources are needed, multiple threads use only a fraction of the resources used by multiple processes.
Benefit of using threads - INTERACTIVE RESPONSIVENESS
Separate computation and I/O threads. I/O threads (in interactive situations), return quickly, giving better response times.
Benefit of using threads - PARALLEL EXECUTION
Threads provide a mechanism to achieve real parallelism. Different threads can run on different machines, and this can happen transparently in the case of multiple processors (user does nothing special).
In Java, a thread can be in one of FOUR STATES. Specify and describe the RUNNABLE state.
RUNNABLE - occurs when you invoke “start” on a thread
In Java, a thread can be in one of FOUR STATES. Specify and describe the BLOCKED state.
BLOCKED - occurs when someone calls “sleep()”, “suspend()” or the “wait()” method. Also when the thread calls an operation that is blocking on input/output.
In Java, a thread can be in one of FOUR STATES. Specify and describe the TERMINATED state.
TERMINATED - a thread terminates if
- it dies a natural death because the “run” method exits
- someone invokes its “stop” method