代写代考 Concurrent Programming

Concurrent Programming
Dr. Bystrov
School of Engineering Newcastle University
Concurrent Programming

Copyright By PowCoder代写 加微信 powcoder

Concept Modelling Examples
Concurrent Programming

Concurrent execution – baseline
The baseline idea is very simple:
CPU switches fast between the concurrent activities (tasks, threads or processes)
mechanisms and libraries for task control means for data communication
means of protecting the shared data from access conflicts
The details are not simple and need to be discussed…
Concurrent Programming

echo “proc”
Process as an instance of the executed program. foreground – one process or pipeline at a time:
sleep 5; echo proc1; sleep 10; echo
cat | tr a-z A-Z
background – many processes concurrently:
(sleep 5; echo proc1; sleep 10; echo
(sleep 1; echo proc1) & echo proc2 &
Concurrent Programming

Fork-join example
Concurrent Programming

to finish;
exit – stops the process.
Processes in C
fork – creates a new child process, the exact copy of the parent process;
exec – replaces the task of the process by overwriting it; wait – primitive synchronisation by waiting for the process
fork + exec – creates a new process, different from the parent.
Concurrent Programming

print (“One”);
pid=fork(); print(“Two”);
AB print (“One”);
print (“One”); pid=fork(); print(“Two”); PC
pid=fork(); print(“Two”); PC
Before After
Concurrent Programming

print (“One”);
execl(“/bin/ls”); print(“Two”);
/*1st line of ls*/
Before After
Concurrent Programming

Concurrent Programming

Conclusions
The schedulers implement the mechanism of concurrency
Fork-join, choice-merge, arbitration when accessing common resource
Two types of dependency between processes
imposed by start-termination control imposed by data communication
Modelling concurrent computations with Petri nets Experiments
Concurrent Programming

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com