Lecture 6 Flashcards

1
Q

How are tasks carried out in shared memory vs distributed memory in terms of processes and threads?

A

Shared memory: starts a single process and forks threads. Threads carry out tasks.

Distributed memory: starts multiple processes since each process operates in its own memory space. Processes carry out tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Critical section?

A

Section of code where resources are accessed and manipulated.
It is a part of the code that must be executed atomically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Mutex?

A

Mutual exclusion lock.
Used to protect critical sections.
Two operations: Locking (acquiring) and Unlocking (releasing).

my_val = Compute_val(my_rank);
Lock(&add_my_val_lock);
x += my_val;
Unlock(&add_my_val_lock);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Busy-waiting?

A

A technique in concurrent programming where a thread or process repeatedly checks for a certain condition to become true. Like being stuck in a while loop until its condition is satisfied.

Waste of computer resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Semaphores?

A

A counter that can be incremented or decremented atomically.

Signal (release or “V”): increments the semaphore value by a specific amount. If other threads or processes were blocked, waiting for the semaphore value to become positive, signal can unblock one or more of them.

Wait (acquire or “P”): decrements the semaphore value by one. If this becomes negative, the thread or process attempting to acquire the semaphore is blocked and put into a waiting state until the semaphore value becomes non-negative.

These are atomic. So “wait” can’t be called simultaneously.

Mutex locks and binary semaphores.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

POSIX Threads?

A

Pthreads.
Standard for Unix-like operating systems.
Specifies an API for multi-threaded programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do threads work in a C program?

A

Call pthread_create() to create a new thread.

Call pthread_join() once for each thread. A single call to pthread_join() will wait for the thread associated with the pthread_t() object to complete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly