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
Optional monitors #3547
Optional monitors #3547
Conversation
This needs a review, to avoid rotting like other pull requests. |
Very insightful comment. Anywho:
|
I suppose we'll need some kind of |
@AndrejMitrovic, __traits(hasMember, "__monitor") should work. |
Yeah, good point. :) |
Well, my changes to druntime include adding @monitor attrs to some classes. Otherwise the code would not compile there =).
I'm not sure if it needs to be covered explicitly. This is a pretty basic feature, that almost any code should cover it. However i would welcome any good test snippets for that. |
Wouldn't the way the code is currently implemented trigger on all structs called Also, yes, this absolutely needs a test case that checks if the attribute actually causes the monitor field to be emitted. Otherwise, we'll end up with a silent performance regression (and inadvertent ABI change) at some point or another. A simple test could consist of verifying |
You're right. It works exactly as you're saying. But i'm not sure here how to fix that. One way would be using some trickier keyword instead of "monitor".
Done in druntime. |
I don't quite understand what the benefit of this is over just having a Monitor type? Presumably it allows you to Signal or Wait on any class decorated with @monitor? Why is that much better than having a library Monitor type? |
@schancel the monitors as they are currently implemented allow to lock/unlock an instance, but not signal/wait. And we already have such type - Mutex =). This PR is aimed is to remove a hidden __monitor field from the Object class, without breaking old behavior. |
Rebased. |
@andralex @WalterBright Please state your view on this subject (again) and let's inact it. |
I'm not really happy with the druntime hash table stuff, but I would totally support a deprecation from implicit monitors to an explicit
This would also deprecate the |
I'm in favor of this. The current backward-compatible approach is the way to go, though I agree with @MartinNowak in the long run we may envision complete deprecation. Please rebase and let's push this through. Thanks! |
Half a year later w/o merging this patch the idea still looks sexy to me. |
Well what's going on? |
"All checks have failed" |
Yes, I'm still opposed to adding a global hash and the outlined plan still makes sense. |
Let's proceed with stage 1 for when 2.071 opens then? Do we have available documentation / rationale on the deprecated features page? Or a DIP? |
Sure, a small entry on http://dlang.org/deprecate.html would be nice, a DIP would be overkill IMHO. |
Cirrus CI: Add FreeBSD 11 pipeline Signed-off-by: Razvan Nitu <RazvanN7@users.noreply.github.com> Merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>
This PR introduces optional monitors feature.
The whole idea is that Object doesn't contain __monitor field anymore.
TypeInfo_Class will hold a monitor offset, if a class has one (by marking class declaration with @monitor attribute), or 0.
Monitor lookup is done with a hash map, if monitorOffset is 0.
The hash map is protected by a primitive RW spin lock.
Monitor finalization will only lookup for monitors, if a monitor was allocated at least once for the type of object being finalized.
druntime counterpart: dlang/druntime#789
discussion: http://forum.dlang.org/thread/xpliectmvwrwthamquke@forum.dlang.org