Supporting tech Flashcards
What can a process be thought of?
Process = program in execution
Has:
- Code that is executing
- Data operated on
- Execution state
Run on a single machine
What is included in execution state?
- Register contents
- PC
- Call stack
- etc,
What does a distributed application consist of?
Consists of processes running on different machines that communicate with each other via a network
What are threads?
Threads are cheaper alternatives to processes
- commonly referred to as “lightwight processes”
May be though of as a memory space (contained code and data) together with a single thread.
- It executes the sequential code that manipulates the process’ data (sharing data with process)
What is meant bu a thread being a “unit of activity” alone?
As an example, it’s like the method/funtion call .
How does more than one thread(“unit of activity”) work in memory space.
Draw a diagram
The memory space is shared among the cooperating, concurrent threads.
The memory space still contains a program (muli-threaded now) and the data it operates on.
What are two core challenges that threads introduce?
- Understand the model of concurrency itself
- new way of thinking
- Ensuring concurrent threads do not interfere with one another.
What is the definition of concurrency?
In general, how does a multi-process program start?
A single process program creates more processes
How are new processes created in a *nix system?
the fork system call. A literal clone of the current running process is created.
What does fork( ) return and why is it significant?
Provide a quick example of what the code looks like
It returns either 0 or the process id (pid) of the child we created.
0 = we are the parent
!0 = we are a child
With this pid difference, everything else is the same.
What is the code sequence you often see in a child process?
The child process then calls to execute a different program
This is done using an “exec” system call.
In general, write basic code that starts a new thread in Java.
public class main { public static void main(String[] args){ Thread thread1 = new MyThread(); thread1.go(); } } public class MyThread implements runnable { private Thread me; public MyThread(){ //constructor } public run(){ //we are off and running in a new thread } public go(){ me = new Thread(self); me.start();//pops over to run } }
What is a race condition?
If we have two threads running that can both access and modify the same variable X (a bank balance) then different results may be seen deperending on the order of accesses to X
The end result depends on which programs get to the data first.
What is the general server code for a Socket Stream?