Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

8/1/2023

Advanced Operating System


CSN-502

Design Issues (Distributed OS)


Issue 1: Time in Distributed Systems

Process Synchronization in Unix

 Mutex and Condition Variables


 Read-Write Locks
 Semaphores

1
8/1/2023

Semaphores

• It is a primitive used to provide synchronization


between various processes or between the various
threads

• Posix named semaphores (process or threads)

• Posix memory-based semaphores (process or


threads)

• System V semaphores (process or threads)

Posix Semaphores
Named Memory based
Semaphore Semaphore
sem_open() sem_init()

sem_wait()
sem_trywait()
sem_post()
sem_getvalue()

sem_close() sem_destroy()
sem_unlink()
4

2
8/1/2023

UNIX IPC

• Persistence of IPC objects

• Process

• Kernel

• File system

• Name Spaces

• Effect of fork, exec and exit on IPC objects

Create a named semaphore (Posix)


int main(int argc, char **argv) {
int flags;
sem_t *sem;
unsigned int value;

flags = O_RDWR | O_CREAT;


value = atoi(argv[2]);

sem = sem_open(argv[1], flags, 0777, value);


sem_getvalue(sem, &value);
printf(“%d\n”, value);
sem_close();
exit(0);
}
6

3
8/1/2023

wait / post for / to a named semaphore (POSIX)

sem = sem_open(argv[1], 0777);


sem_wait(sem);
sem_getvalue(sem, &value);
printf(“value = %d\n”, value);
.
.
sem = sem_open(argv[1], 0777);
sem_post(sem);
sem_getvalue(sem, &value);
printf(“value = %d\n”, value);
.
.
7

Solution: Vector Clocks


Ci is a vector of size n (no. of processes) at process i
Ci(a) is a vector of size n associated with event a referred as
its timestamp
Ci[i] – i’s own logical time
Ci[j] – i’s best guess of the logical time at j (j ≠ i)
Update rules:
 Ci[i] = Ci[i] + d for every event at process i (d > 0)
 if a is send of message m from i to j with vector
timestamp tm = Ci(a), on receive of m at j:
Cj[k] = max(Cj[k], tm[k]) for all k

4
8/1/2023

Assertion.
At any instant
for all i, j: Ci[i] ≥ Cj[i]

Vector Clocks

5
8/1/2023

For events a and b with vector timestamps ta and tb,

•ta = tb iff for all i, ta[i] = tb[i]

•ta ≠ tb iff for some i, ta[i] ≠ tb[i]

•ta ≤ tb iff for all i, ta[i] ≤ tb[i]

•ta < tb iff (ta ≤ tb and ta ≠ tb)

•ta || tb iff (ta < tb and tb < ta)

Relation || is not a partial order because it is not


transitive

(3, 4, 5), (2, 6, 3) and (3, 5, 5)

6
8/1/2023

 a → b iff ta < tb

 Events a and b are causally related iff ta < tb or tb < ta,


else they are concurrent

 System of vector clocks allows us to order events and


decide whether two events are causally related or
not by simply looking at the timestamps of the events

 Total order?

This is still not a total order

Voldemort is a distributed data store that was


designed and used by LinkedIn for highly-
scalable storage

Amazon DynamoDB

You might also like