You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/practice/bank-account/.approaches/readwrite-lock/content.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,10 +85,10 @@ class BankAccount {
85
85
}
86
86
```
87
87
88
-
A [ReadWriteLock][docs-readwritelock] provides two types of locks - one for reading the other for writing.
88
+
A [ReadWriteLock][docs-readwritelock] provides two types of locks - one for reading, the other for writing.
89
89
[ReentrantReadWriteLock][docs-reentrantreadwritelock] is an implementation of a [ReadWriteLock][docs-readwritelock].
90
90
91
-
Read locks are intended for readonly type operations, such as `getBalance`, and is acquired by calling `readLock().lock()` on the [ReadWriteLock][docs-readwritelock].
91
+
Read locks are intended for read-only type operations, such as `getBalance`, and are acquired by calling `readLock().lock()` on the [ReadWriteLock][docs-readwritelock].
92
92
Multiple threads are allowed to acquire read locks at the same time because they are expected to only read data.
93
93
This means multiple threads can run `getBalance` at the same time.
94
94
@@ -99,7 +99,7 @@ Write locks are acquired by calling `writeLock().lock()` on the [ReadWriteLock][
99
99
Only one thread can hold a write lock at a time.
100
100
Therefore, `withdraw`, `deposit`, `open` and `close` can not run at the same time.
101
101
Additionally, a thread must _also_ wait for _all_ read locks to be released to obtain a write lock.
102
-
Similarly, threads must wait for write locks to be released before they granted a read lock.
102
+
Similarly, threads must wait for write locks to be released before they are granted a read lock.
103
103
This means `getBalance` also can not run at the same time as any of the `withdraw`, `deposit`, `open` and `close` methods.
104
104
105
105
The locks are released in the `finally` block to ensure they are released, even when an exception is thrown.
0 commit comments