D Mutex reference.
Saaa
empty at needmail.com
Fri Jan 19 04:03:00 PST 2007
I'm not really doing OOP, or am I reading it incorrectly again?
What is the object reference?
I just use a simple (never-ending) function for the data generation.
Should I just encapsulate this function in synchronize?
Thanks, Saaa
>>> http://digitalmars.com/d/statement.html#SynchronizedStatement
>>>
>>> Does this one help?
>>
>> Thanks for the reply.
>> I have one thread generating alot of data and main reading a few of them
>> every 10ms or so.
>> This can be a problem, right? (when main tries to read some data which
>> hasn't been writting completely?)
>
> Actually, yes.
>
>> Reading about multi threading pointed me to mutexes, but I can't find any
>> reference.
>> Synchronized only locks a part of the code, not the actual data?
>
> The point of synchronized blocks is, that you can finish what ever you do
> with your data, without getting interrupted by another thread.
>
> There are two ways to use synchronized:
>
> a) standalone, so it's like Windows' critical sections:
>
> synchronized {
> /* ... code ... */
> }
>
> b) synchronized with an object
>
> "synchronized (Expression), where Expression evaluates to an Object
> reference, allows only one thread at a time to use that Object to execute
> the ScopeStatement. If Expression is an instance of an Interface, it is
> cast to an Object."
>
> synchronized ( /* expression or object */ ) {
> /* ... code ... */
> }
>
> Apparently, b) should be the way to go for you.
>
> Best regards,
> Alex
>
More information about the Digitalmars-d-learn
mailing list