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
@@ -112,7 +113,7 @@ use happylock::{ThreadKey, Mutex};
112
113
113
114
fnmain() {
114
115
// each thread can only have one thread key (that's why we unwrap)
115
-
// ThreadKey is not Send, Sync, Copy, or Clone
116
+
// ThreadKey is not Send, Copy, or Clone
116
117
letkey=ThreadKey::get().unwrap();
117
118
118
119
letmutex=Mutex::new(10);
@@ -153,6 +154,8 @@ fn main() {
153
154
}
154
155
```
155
156
157
+
This `LockCollection` can be implemented simply by releasing the currently acquired locks and retrying on failure
158
+
156
159
---
157
160
158
161
## The Lockable API
@@ -266,7 +269,17 @@ Time Complexity: O(nlogn)
266
269
267
270
## Problem: Live-locking
268
271
269
-
Although this library is able to successfully prevent deadlocks, livelocks may still be an issue. Imagine thread 1 gets resource 1, thread 2 gets resource 2, thread 1 realizes it can't get resource 2, thread 2 realizes it can't get resource 1, thread 1 drops resource 1, thread 2 drops resource 2, and then repeat forever. In practice, this situation probably wouldn't last forever. But it would be nice if this could be prevented somehow.
272
+
Although this library is able to successfully prevent deadlocks, livelocks may still be an issue.
273
+
274
+
1. Thread 1 locks mutex 1
275
+
2. Thread 2 locks mutex 2
276
+
3. Thread 1 tries to lock mutex 2 and fails
277
+
4. Thread 2 tries to lock mutex 1 and fails
278
+
5. Thread 1 releases mutex 1
279
+
6. Thread 2 releases mutex 2
280
+
7. Repeat
281
+
282
+
This pattern will probably end eventually, but we should really avoid it, for performance reasons.
270
283
271
284
---
272
285
@@ -384,8 +397,8 @@ This is what we were trying to avoid earlier
384
397
This is what I used in HappyLock 0.1:
385
398
386
399
```rust
387
-
structReadLock<'a, T(&'aRwLock<T>);
388
-
structWriteLock<'a, T(&'aRwLock<T>);
400
+
structReadLock<'a, T>(&'aRwLock<T>);
401
+
structWriteLock<'a, T>(&'aRwLock<T>);
389
402
```
390
403
391
404
**Problem:** This can't be used inside of an `OwnedLockCollection`
@@ -413,7 +426,7 @@ unsafe trait Lockable {
413
426
414
427
---
415
428
416
-
## Not every lock can be read doe
429
+
## Not every lock can be read tho
417
430
418
431
```rust
419
432
// This trait is used to indicate that reading is actually useful
0 commit comments