From 5c511c36e82a13e33c68bc8913335aa019691cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=9B=8B=E7=96=BC=E7=9A=84=E8=9B=8B=E8=9B=8B?= Date: Sat, 26 Aug 2023 15:11:26 +0800 Subject: [PATCH] =?UTF-8?q?Update=20global-variable.md(next=5Fid=E5=8F=96?= =?UTF-8?q?=E5=80=BC=E9=94=99=E8=AF=AF=EF=BC=9F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Atomic*::fetch_* 函数返回值为上一个值,next_id的取值是不是错了? --- src/advance/global-variable.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/advance/global-variable.md b/src/advance/global-variable.md index 0148ee9c..66492d87 100644 --- a/src/advance/global-variable.md +++ b/src/advance/global-variable.md @@ -93,7 +93,8 @@ fn generate_id()->usize{ if current_val > MAX_ID{ panic!("Factory ids overflowed"); } - let next_id = GLOBAL_ID_COUNTER.fetch_add(1, Ordering::Relaxed); + GLOBAL_ID_COUNTER.fetch_add(1, Ordering::Relaxed) + let next_id = GLOBAL_ID_COUNTER.load(Ordering::Relaxed); if next_id > MAX_ID{ panic!("Factory ids overflowed"); }