Large (>32 byte) concurrency messages
Ali Çehreli
acehreli at yahoo.com
Thu Aug 8 14:11:06 PDT 2013
On 08/08/2013 01:08 PM, JR wrote:
> The first concurrency message passed is a string, which works as
> expected. The second message is the translated struct of over 32 bytes
> in size (96 to be exact), and that's where things start breaking.
I came across the following bug just the other day. It may be related:
"std.concurrency send() fails with structs over 32 bytes"
http://d.puremagic.com/issues/show_bug.cgi?id=10740
> Passing an immutable pointer *initially* works, but then you get a race
> to finish using the struct before the scope it was declared in ends.
An immutable on the receiving side is a request to the caller that the
data must be immutable. If you are casting data with mutable indirection
to immutable, anything can happen.
immutable data is by nature not synchronized because it is read-only.
(Of course you can synchronize if you know that it is casted data to
begin with.)
Have you considered the 'shared' attribute? You are still responsible
for dealing with race conditions.
> Are there any easy workarounds?
Messages are supposed to solve race conditions. Once a message gets some
data nobody else should write to that data.
> Do people use std.concurrency, or is it largely avoided?
I have used it only in test code. I am not aware of major problems other
than some Variant-related issues that you also mention.
Ali
More information about the Digitalmars-d-learn
mailing list