-
Notifications
You must be signed in to change notification settings - Fork 2
/
distributedReadWriteLock.py
64 lines (45 loc) · 1.62 KB
/
distributedReadWriteLock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -----------------------------------------------------------------------------
# Distributed Systems (TDDD25)
# -----------------------------------------------------------------------------
# Author: Sergiu Rafiliu (sergiu.rafiliu@liu.se)
# Modified: 31 July 2013
#
# Copyright 2012 Linkoping University
# -----------------------------------------------------------------------------
"""Class implementing a distributed version of ReadWriteLock."""
import threading
from . import readWriteLock
class DistributedReadWriteLock(readWriteLock.ReadWriteLock):
"""Distributed version of ReadWriteLock."""
def __init__(self, distributed_lock):
readWriteLock.ReadWriteLock.__init__(self)
# Create a distributed lock
self.distributed_lock = distributed_lock
#
# Your code here.
#
pass
# Public methods
def write_acquire(self):
"""Acquire the rights to write into the database.
Override the write_acquire method to include obtaining access
to the rest of the peers.
"""
print("INTO WRITE")
#readWriteLock.ReadWriteLock.write_acquire()
self.distributed_lock.acquire()
#
# Your code here.
#
pass
def write_release(self):
"""Release the rights to write into the database.
Override the write_release method to include releasing access
to the rest of the peers.
"""
#
# Your code here.
#
self.distributed_lock.release()
#readWriteLock.ReadWriteLock.write_release()
pass