Lecture 6 - Concurrency Intro Flashcards
What is concurrency?
The ability of different program parts to be executed simultanously.
How many ways of having concurrency is there?
2
What are the 2 ways of having concurrency?
- shared memory (one memory location used by different parts of the program running at the same time)
- message passing (different memory locations, is more robust)
What does shared memory concurrency require?
Synchronisation between parts of the prgram which are to run alongside each other.
What is parallelism?
Simply about making your program faster. There is usually no need to have threads, it just so happens that a program can be run in parallel when there are mutliple processors.
How is concurrency different to parallelism?
Concurrency is a programming paradigm, where threads are used to get asynchronous events from the enviroment (no waiting on program, other threds can continue) or structuring program as a collection of interacting agents.
Concurrency has?
different independent processes being executed
- dealing with lot of things at once
What does parallelism have?
simulatnous execution of related computations
- doing lot of things at once
What is a process?
Process is a program with its own memory address space.
How many processes can be executed simulatneouly?
Many, CPU does it all the time.
What is a thread?
independent sequence of program instructions. a process can have multiple threads, sharing the same address space.
-> can be executed simultanously
-> essentially a subset of a process
Lifecycle of a thread:
- create
- start (possibly with arguments)
- each is given an identifier
-> can be used to kill / pause / interrupt - teminated
In shared memory how does communication between threads happen?
By modifying the shared memory space.
What are POSIX threads?
threading implementation in C
What flag has to be specified with the clang compiler to compile code with POSIX threads?
-lpthread
What is the posix thread create method?
pthread_create(thread , thread attr ,function , argument to function)
What is the posix thread join method?
pthread_join(thread, NULL (result))
What does pthread_create return when successfully creating a thread?
0 - refer to slide 8
What is pthread_Join do?
What does it return when successfully
Waits for a another thread to terminate before terminating.
Returns 0 when successful.
Refer to slide 9