From e16ed7f33654806d99076960b172033623139fb3 Mon Sep 17 00:00:00 2001 From: ThePuzzlemaker Date: Wed, 6 Jan 2021 17:21:03 -0600 Subject: [PATCH] Fix Arc Clone --- src/arc-clone.md | 6 +++--- src/arc-final.md | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/arc-clone.md b/src/arc-clone.md index cfa1db6..a607d9d 100644 --- a/src/arc-clone.md +++ b/src/arc-clone.md @@ -55,7 +55,7 @@ machines) incrementing the reference count at once. This is what we'll do. It's pretty simple to implement this behaviour: ```rust,ignore -if old_rc >= isize::MAX { +if old_rc >= isize::MAX as usize { std::process::abort(); } ``` @@ -77,9 +77,9 @@ impl Clone for Arc { let inner = unsafe { self.ptr.as_ref() }; // Using a relaxed ordering is alright here as knowledge of the original // reference prevents other threads from wrongly deleting the object. - inner.rc.fetch_add(1, Ordering::Relaxed); + let old_rc = inner.rc.fetch_add(1, Ordering::Relaxed); - if old_rc >= isize::MAX { + if old_rc >= isize::MAX as usize { std::process::abort(); } diff --git a/src/arc-final.md b/src/arc-final.md index 1bcec56..df41f45 100644 --- a/src/arc-final.md +++ b/src/arc-final.md @@ -46,16 +46,14 @@ impl Deref for Arc { } } -use std::sync::atomic::Ordering; - impl Clone for Arc { fn clone(&self) -> Arc { let inner = unsafe { self.ptr.as_ref() }; // Using a relaxed ordering is alright here as knowledge of the original // reference prevents other threads from wrongly deleting the object. - inner.rc.fetch_add(1, Ordering::Relaxed); + let old_rc = inner.rc.fetch_add(1, Ordering::Relaxed); - if old_rc >= isize::MAX { + if old_rc >= isize::MAX as usize { std::process::abort(); }