Sharing in D

downs default_357-line at yahoo.de
Fri Aug 1 00:47:52 PDT 2008


Walter Bright wrote:
> downs wrote:
>> Walter Bright wrote:
>>> downs wrote:
>>>> IMHO, however, most global variables are intended to be
>>>> instantiated only once, not once per thread. Because of this, the
>>>> success of this model hinges on how easy an object can be
>>>> transferred between threads. Some sort of language enforced
>>>> blocking, maybe?
>>> The idea is to no longer allow unsynchronized uncontrolled sharing
>>> of data between threads as the *default* behavior. If you want to
>>> do it, you'll have to do it *intentionally*.
>>>
>>
>> Yeah, but I'd like a way to do it that doesn't leave me entirely on
>> my own, considering that it's imho a common use-case.
> 
> I don't understand what you're asking for.

Sorry.

I am looking for a safe way to transfer ownership of a single object between threads.

Like, for instance, a "unique Object foo" would behave like a shared Object, but the compiler would treat it like a nonshared object for purposes of optimization, and all accesses from the outside would be implicitly synchronized.

This could be used for objects that really are only supposed to exist once, but still used in a multithreaded way.

Hope that clears things up.



More information about the Digitalmars-d mailing list