digitalmars.D - Phobos and shared
- d coder <dlang.coder gmail.com> Mar 15 2011
- Nick Treleaven <nospam example.net> Mar 16 2011
- SHOO <zan77137 nifty.com> Mar 16 2011
- Nick Treleaven <nospam example.net> Mar 17 2011
--bcaec51f98610d358c049e862a36
Content-Type: text/plain; charset=ISO-8859-1
Greetings
I am trying to create a multithreaded application. Right now I am finding it
difficult to work with "shared" qualifier. One of the reasons is that Phobos
library does not seem compatible with "shared" data-structures. For example:
import std.bitmanip;
shared BitArray foo;
void main() {
foo ~= true; // this does not work
(cast(BitArray)foo) ~= true; // Even casting does not help
}
I know that "shared" is a relatively new qualifier in D2. Are there plans to
make Phobos "shared" compatible?
Are there any workarounds that I am missing.
Regards
- Puneet
--bcaec51f98610d358c049e862a36
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Greetings<div><br></div><meta http-equiv=3D"content-type" content=3D"text/h=
tml; charset=3Dutf-8"><div>I am trying to create a multithreaded applicatio=
n. Right now I am finding it difficult to work with "shared" qual=
ifier. One of the reasons is that Phobos library does not seem compatible w=
ith "shared" data-structures. For example:</div>
<div><br></div><div><div>import std.bitmanip;</div><div>shared BitArray foo=
;</div><div>void main()=A0{</div><div>=A0 foo ~=3D true;<span class=3D"Appl=
e-tab-span" style=3D"white-space:pre"> </span>// this does not work</div>=
<div>
=A0 (cast(BitArray)foo) ~=3D true;<span class=3D"Apple-tab-span" style=3D"w=
hite-space:pre"> </span>// Even casting does not help</div>
<div>}</div></div><div><br></div><div><br></div><div>I know that "shar=
ed" is a relatively new qualifier in D2. Are there plans to make Phobo=
s "shared" compatible?</div><div>Are there any workarounds that I=
am missing.</div>
<div><br></div><div>Regards</div><div>- Puneet</div>
--bcaec51f98610d358c049e862a36--
Mar 15 2011
On Tue, 15 Mar 2011 19:52:14 +0530, d coder wrote:import std.bitmanip; shared BitArray foo; void main() { foo ~= true; // this does not work (cast(BitArray)foo) ~= true; // Even casting does not help } I know that "shared" is a relatively new qualifier in D2. Are there plans to make Phobos "shared" compatible?
I'm certainly no expert, but it seems the cast is the problem - this causes an error: auto f = cast(BitArray)foo; shared.d(21): Error: function std.bitmanip.BitArray.opCast () is not callable using argument types () shared.d(21): Error: cannot implicitly convert expression (foo.opCast()) of type void[] to BitArray Without shared, the cast is fine. It seems the problem is casting a shared struct instance that defines opCast (at least like BitArray.opCast, returning void[]).Are there any workarounds that I am missing.
If you're desperate, you can use __gshared instead of shared but this is then completely up to you to ensure no data races for foo.
Mar 16 2011
This is the very interesting agenda.
I know a method, but don't know that the method is recommended:
import std.bitmanip;
shared BitArray foo;
void main(){
(*cast(BitArray*)&foo) ~= true;
}
In addition, your code is filled up many 'cast' if you try to solve it
by this method.
This is clearly unfavorable.
See also: http://www.informit.com/articles/article.aspx?p=1609144
This article says that the basic policy about the multi-thread uses
message passing. When you use message passing, these problems rarely occur.
However, it is important that it is easily feasible even if it is other
methods.
I want to know a policy about this agenda.
--
SHOO
(2011/03/15 23:22), d coder wrote:
Greetings
I am trying to create a multithreaded application. Right now I am
finding it difficult to work with "shared" qualifier. One of the reasons
is that Phobos library does not seem compatible with "shared"
data-structures. For example:
import std.bitmanip;
shared BitArray foo;
void main() {
foo ~= true;// this does not work
(cast(BitArray)foo) ~= true;// Even casting does not help
}
I know that "shared" is a relatively new qualifier in D2. Are there
plans to make Phobos "shared" compatible?
Are there any workarounds that I am missing.
Regards
- Puneet
Mar 16 2011
On Wed, 16 Mar 2011 17:42:09 +0000, Nick Treleaven wrote:auto f = cast(BitArray)foo; shared.d(21): Error: function std.bitmanip.BitArray.opCast () is not callable using argument types () shared.d(21): Error: cannot implicitly convert expression (foo.opCast()) of type void[] to BitArray Without shared, the cast is fine. It seems the problem is casting a shared struct instance that defines opCast (at least like BitArray.opCast, returning void[]).
This seems like a compiler bug, so filed: http://d.puremagic.com/issues/show_bug.cgi?id=5747
Mar 17 2011









Nick Treleaven <nospam example.net> 