m_condition.mutex cannot be used in shared method ?
Sean Kelly via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 19 10:09:22 PDT 2014
On Sunday, 19 October 2014 at 13:42:05 UTC, Marco Leise wrote:
> I have a thread that is shared by
> others, so I have a shared method, inside of which I wrote:
>
> final void opOpAssign(string op : "~")(ref StreamingObject
> item) shared
> {
> synchronized (m_condition.mutex)
> {
> m_list.unshared ~= item;
> m_condition.notify();
> }
> }
>
> Error: non-shared method core.sync.condition.Condition.mutex is
> not callable using a shared object
>
> Where exactly should my stuff stop to be shared so I can call
> .mutex ?
What really needs to happen is for everything in core.sync to be
made shared. I got partway through this at one point and
stopped, because it was imposing a terrible design on the
classes--I had shared methods that were casting away shared and
then calling the non-shared methods to do the work.
The reason for this was that the transitivity of shared was
preventing me from calling pthread_mutex_lock or whatever because
those functions didn't take a shared pthread_mutex_t. And
attempting to rewrite core.sys.posix to make the logically shared
types explicitly shared had a cascading effect that made me
uncomfortable.
Because of this, I remain unconvinced that the semantics of the
shared attribute are actually correct when applied to
user-defined types. I want some kind of an "I know what I'm
doing" label, perhaps equivalent to the "mutable" attribute in
C++, but to exempt contained types from shared.
More information about the Digitalmars-d-learn
mailing list