Presentation is loading. Please wait.

Presentation is loading. Please wait.

Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________.

Similar presentations


Presentation on theme: "Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________."— Presentation transcript:

1

2 Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________ -- light weight process ____________ -- user processes for O.S. interaction

3 _______ a process ____________ a process __________ a process ____________ a process Example: a terminal application shell (OS X) How do you... 1) Create a shell? 2) Start the execution of a shell? 3) Suspend a shell? 4) Destroy a shell?

4 Example 2: Unix commands in a C-shell What suffix is used to cause a Unix command to run in the background? What command suspends & destroys a running process? Example 3: Dijkstra’s parbegin - parend parbegin process 1 ; process 2 ; process 3 ;  process n ; parend

5 Example 4: Unix script programs  A fork function creates a child process and that shares code with the parent. sample  The fork function returns the child process ID to its parent and 0 to the child.  Both the child and its parent continue executing immediately following the fork.  Suspending and resuming process execution is determined by the O.S.  Children processes share resources (files, etc.) with their parent.  Processes are killed at the end of their code.  A wait function can be called to suspend a parent awaiting a child. childProcessNum = fork(); if (childProcessNum==0) { // child process code goes here } else { // parent process code goes here  do { finiNum = wait(status); } while (finiNum!=childProcessNum) }

6 Linux - C #include void *thread1code(void *arg) { //code for Thread 1 goes here return arg; } void *thread2code(void *arg) { //code for Thread 2 goes here return arg; } int main() { int errcode; pthread_t thread1, thread2; /* holds thread info */ int *status; /* holds return code */ if (errcode=pthread_create(&thread1, NULL, thread1code, NULL)) printf("Thread 1 creation failed\n"); if (errcode=pthread_create(&thread2, NULL, thread2code, NULL)) printf("Thread 2 creation failed\n"); // code for the main thread goes here pthread_join(thread1,(void *) &status); pthread_join(thread2,(void *) &status); exit(0); } Example 5: C/C++ Threads C and C++ require the use of OS-specific libraries.

7 Example C/C++: Threads Windows - C++ #include "stdafx.h” #include using namespace DWORD WINAPI thread_code_a(void *junk) { // code for Thread a goes here return 0; } DWORD WINAPI thread_code_b(void *junk) { // code for Thread b goes here return 0; } int main() { DWORD thread_a, thread_b; CreateThread(NULL, 0, thread_code_b, NULL, 0, &thread_b); CreateThread(NULL, 0, thread_code_a, NULL, 0, &thread_a); // more main thread code goes here return 0; }

8 Example 6: Ada Tasks  An Ada task is created and begins execution when its enclosing program unit executes. sample  Each task has a single line of control.  A program terminates only when all its tasks terminate. with text_io; use text_io; procedure Write_em is task WriteAs; task body WriteAs is begin for j in 1..10 loop put('A'); new_line; end loop; end WriteAs; task WriteBs; task body WriteBs is begin for j in 1..10 loop put('B'); new_line; end loop; end WriteBs; begin -- Write_em procedure null; -- procedure body must be have least one instruction end Write_em;


Download ppt "Synonyms: A _______ is a unit of software that is capable of executing concurrently with other similar units. _______ -- user-defined process in Ada _________."

Similar presentations


Ads by Google