Module 1 Flashcards
(27 cards)
What is the difference between multitasking and multithreading?
Multitasking is when several applications seem to run at the same time.
Multithreading is a form of multitasking within an application.
What is concurrent programming?
Concurrent programming is to make two or more task seemingly (almost) execute at the same time. (Sharing the computers CPU)
What is parallel programming?
Parallel programming is when two or more tasks run exactly at the same time. (Not sharing the computers CPU).
What is a process?
An instance of an application being executed.
What does a process consist of?
Program instructions to the machine.
Stack memory (call stack) - to keep track of active methods.
A heap memory.
A program counter (register).
Other resources, security information, information about the state of the process etc.
Is a process isolated from other processes?
Yes, a process runs in it’s own address space managed by OS and is totally isolated from other processes.
What is a thread?
A single sequential flow of control within a program
What does all threads within the same process share?
Adress space, code and data
What’s the difference between threads and processes?
A process is the execution of a program, isolated from other processes. It runs in its own memory space.
A thread runs within the address space of a process. It is a execution of the whole or parts of a program. Threads share the process memory area.
Does every process has a thread?
Yes, every process has at least one thread. More threads can be created in the process.
What is concurrency?
A property of a computing system in which several tasks are executing simultaneously. Systems are (or seem to be) progressing at the same time.
Running several programs at the same time is an example.
Name two types of concurrency
Multithreading and parallel programming
What is a sequential application?
A sequential application has one single thread of execution.
A sequence of statements that are executed one after another.
True or false:
A concurrent application has multiple threads of execution.
True
True or false:
A sequential application has one single thread of execution.
True
How can parallelism be achieved in an application?
By splitting the application into smaller tasks where they can be executed in parallel.
Can both concurrency and parallelism be achieved in a single-core CPU?
No, concurrency can but not parallelism.
What is the difference between parallelism and concurrency?
Parallelism: Running exactly at the same time. Two applications run purely parallel, each in a separate processor.
Concurrency: Running seemingly at the same time. The processor shares its time to program with so short intervals that it gives the users the illusion of programs running in parallel.
True or false:
Parallelism can be considered as a form of concurrency.
True
What are the main advantages with multithreading?
Performance and responsiveness.
Name some typical thread states.
Ready
Running/active
Blocked/waiting
Terminated
What are the two ways to create and start a thread in java?
Provide a Runnable object by implementing the interface Runnable which defines a single method called run. Subclass the Thread class and override the run method. In both cases Thread.start() is used to start the thread.
What does the Thread.join() method do?
It allows one thread to wait for the completion of another
Name some other useful methods in the Thread class
T.isAlive();
T.interrupt();
Thread.currentThread().getName();
Thread.currentThread().getID();