Skip to content

let initOnce take a shared Mutex #5661

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

Merged
merged 2 commits into from
Sep 14, 2017

Conversation

aG0aep6G
Copy link
Contributor

As initiated by @ZombineDev (#4551 (comment)).

Depends on #4551 (included here) and dlang/druntime#1605.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 28, 2017

Thanks for your pull request, @aG0aep6G! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@@ -2502,14 +2502,20 @@ auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex)
return var;
}

deprecated("use the overload that takes a `shared(Mutex)`")
auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Should we deprecate code that's been using __gshared mutexes without issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not (yet). Mutex didn't work with shared at all for the longest time, and I'm not even sure how well it fits within the (theoretical) shared model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not (yet).

Ok, how about changing the deprecation to a comment in the docs indicating that the this non-shared overload may be deprecated in the future, so to discourage the use in new code.

Mutex didn't work with shared at all for the longest time

Yeah, it was a shame. Now that dlang/druntime#1728 is merged we should be good, no?

I'm not even sure how well it fits within the (theoretical) shared model.

@klickverbot Can you take a look at http://dlang.org/phobos-prerelease/core_sync_mutex and the source and check if there's anything that can be improved w.r.t. the correct use of the shared type qualifier?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, how about changing the deprecation to a comment in the docs indicating that the this non-shared overload may be deprecated in the future

Yep, anything like that would be fine – the point is just to decouple allowing shared from forcing it, as the former is entirely uncontroversial. As for the latter, I don't currently see any issues with Mutex and shared as it stands (unless we end up moving towards more ownership-based semantics), but as long as we don't have shared nailed down, it seems unwise to break too much code that is just as valid without it.

Actually, thinking about it: Even if shared actually implied non-thread-local right now, it seems like calling initOnce with a thread-local mutex wouldn't be invalid. Requiring shared would just serve to catch bugs where a thread-local mutex is passed by accident (e.g. by leaving shared off a static variable).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've un-deprecated the unshared overload. Not adding a comment about future deprecation, because it's not clear (to me) what's going to happen.

@aG0aep6G aG0aep6G force-pushed the initOnce-shared-Mutex branch from 924852a to 82fe75f Compare September 2, 2017 21:41
Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a lot nicer :)
Thanks for pushing this!

@dlang-bot dlang-bot merged commit 6fed27c into dlang:master Sep 14, 2017
@aG0aep6G aG0aep6G deleted the initOnce-shared-Mutex branch September 18, 2017 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants