-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] What is purpose of Phantomdata in LockGuard? (api.rs) #667
Comments
Yes. This enforces that the lock not be unlocked by threads other than the thread that acquired the lock. |
Thanks. Then why do we implement Send or Sync for LockGuard? |
hmm that's weird. |
Doesn't Send make sense when T is Send? As I understand it, PhantomData is there to prevent LockGuard being derived as general Send and Sync, and the impl is there to make it available for special cases. |
Ok, I did some searching, and this is actually a pretty interesting problem.
|
Thank you so much! Now I see the point. |
As far I understood, phantomdata is for mimicking as if the type stores a value of type T.
Why do we need this in struct LockGuard? The type T is *const (), which is !Send + !Sync.
At first I thought it is to make LockGuard not Sendable and Syncable, but I'm not sure. Is it right?
The text was updated successfully, but these errors were encountered: