Comments (2)
I'm not sure why you see the significant difference because std::hint::spin_loop()
is merely a hint and architecture-dependent feature. But if you see the documentation for those functions and read the exact code, you can get some idea:
backoff.snooze()
: https://docs.rs/crossbeam/latest/crossbeam/utils/struct.Backoff.html#method.snoozestd::hint::spin_loop()
: https://doc.rust-lang.org/std/hint/fn.spin_loop.html
The implementation of backoff.snooze()
not only calls std::hint::spin_loop()
but also calls yield_now()
, which explicitly yields the current execution of this thread to the OS and asks for OS to execute other threads to make progress. Since std::hint::spin_loop()
is merely a hint to CPU and does not explicitly yields the execution of current thread, probably explicit blocking the thread was effective in your case.
You can understand the situation with the following intuitive explanation (note that this may not be correct; this is just my thought). If one thread fails to acquire the spinlock, then immediate retry is highly likely to fail again. Instead, the thread is better to wait until another thread (the one holding the lock) to finish its task. Thus, using backoff.snooze()
might be more efficient than using std::hint::spin_loop()
.
from cs431.
Thank you for your explanation!
from cs431.
Related Issues (20)
- ---
- Midterm exam rehearsal session (Apr. 8th) / No class on Apr. 10th HOT 2
- Midterm exam on April 15th (Mon), 13:00-15:00 in the lecture room HOT 10
- [Question] Test timed out on cargo_asan --release (HW2) HOT 4
- [Question] Should we consider, for fairness evaluation, that a thread might not `unlock()`? HOT 10
- [Question] Exam problem "a variable can be `drop()`ed using its `&mut` reference" HOT 2
- [Question] Cannot open new browser inside Safe Browser HOT 5
- [HW4] Couldn't Compile cargo test --test boc due to non-existent object file? HOT 2
- [Question] What's the intended answer for 2021 Fall? HOT 2
- [HW4] (Thread Sanitizer has been running for 10 minutes) HOT 6
- [Locks] Can we change while loop of MCSParking lock to If statement? HOT 2
- [Question] Why do we clone a thread instead of using next_ref.thread.unpark? HOT 1
- [Question] `unsafe` on the traits `RawLock` and `RawTryLock` HOT 2
- [Question] Why use AtomicBool instead of non-atomic bool in Node of CLH Lock? HOT 2
- [Question] understanding of BoC HOT 3
- [Question] mem::swap with temporary value HOT 3
- [Question] [HW4] How do SendError and RecvError occur at the same time? HOT 6
- Midterm score is released / Announcement on the midterm claim session HOT 3
- [Homework BOC] How to initialize a behavior HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cs431.