The Wayback Machine - https://web.archive.org/web/20201201004128/https://github.com/microsoft/cpprestsdk/pull/1087
Skip to content
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

Data race on _pplx_g_sched_t::get_scheduler() (#1085) #1087

Closed
wants to merge 2 commits into from

Conversation

@dimarusyy
Copy link
Contributor

@dimarusyy dimarusyy commented Mar 26, 2019

  • Make singleton thread-safe
- fixed
@msftclas
Copy link

@msftclas msftclas commented Mar 26, 2019

CLA assistant check
All CLA requirements met.

- use C++11 compatible implementation
Copy link
Member

@BillyONeal BillyONeal left a comment

I'm going to submit an alternate fix for this, if that's okay?

}

return m_scheduler;

This comment has been minimized.

@BillyONeal

BillyONeal Mar 26, 2019
Member

Bug, needs to return sptr.

{
switch (m_state)
{
sched_ptr sptr = std::atomic_load_explicit(&m_scheduler, std::memory_order_consume);

This comment has been minimized.

@BillyONeal

BillyONeal Mar 26, 2019
Member

Not sure how I feel about memory_order_consume; even SG1 thinks that thing is effectively broken. Any objections to changing this to acquire?

This comment has been minimized.

@dimarusyy

dimarusyy Mar 26, 2019
Author Contributor

consume and acquire should be equivalent here as atomic is not used for synchronization. Anyway, I'll update with acquire.

// This case means the global m_scheduler is not available.
// We spin off an individual scheduler instead.
return std::make_shared<::pplx::default_scheduler_t>();
::pplx::details::_Scoped_spin_lock lock(m_spinlock);

This comment has been minimized.

@BillyONeal

BillyONeal Mar 26, 2019
Member

As far as I am aware, all the major shared_ptr implementations actually use spinlocks to implement this load operation anyway; perhaps we should just drop the check and take the spinlock every time. It does limit scalability of the system but this shared_ptr city wasn't going to win awards for that anyway.

This comment has been minimized.

@dimarusyy

dimarusyy Mar 26, 2019
Author Contributor

Am I right that you suggest to drop double-lock here and just acquire spinlock on every call to get_scheduler()?

This comment has been minimized.

@BillyONeal

BillyONeal Mar 27, 2019
Member

@dimarusyy Yes, that's what my alternative does. Does that solution look acceptable to you?

This comment has been minimized.

@dimarusyy

dimarusyy Mar 27, 2019
Author Contributor

I'm fine as you accepted spinlock acquiring on every call to get_scheduler(). Thanks for comment and update.

@BillyONeal
Copy link
Member

@BillyONeal BillyONeal commented Mar 26, 2019

Can you look at this alternative and let me know if that makes you happy?

@BillyONeal
Copy link
Member

@BillyONeal BillyONeal commented Mar 26, 2019

I mean this alternative: #1088

@BillyONeal BillyONeal closed this Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.