Shared Hell
Kagamin
spam at here.lot
Wed Oct 28 09:47:31 PDT 2009
Denis Koroskin Wrote:
> > As an escape from the type system, you can always cast away the
> > shared-ness.
>
> That's the only way I have now. Casts from shared to unshared *everywhere*:
>
> class BuildManager : BuildListener
> {
> synchronized void build(shared Target target)
> {
> // ...
>
> _buildingThread = new shared(Thread)(&_startBuild); // creating a
> new shared Thread. Yes, shared Thread, because BuildManager is global.
>
> //_buildingThread.start(); // Error: function
> core.thread.Thread.start () is not callable using argument types () shared
> (cast(Thread)_buildingThread).start(); // works, but ugly, and I
> don't have a reason to hijack the type system in this case
>
> // ...
> }
> }
you can use local variables to not have to cast in every statement.
class BuildManager : BuildListener
{
synchronized void build(shared Target target)
{
// ...
bt = new Thread(&_startBuild);
_buildingThread = cast(shared Thread)bt; //store as shared
bt.start(); //work with non-shared variable normally
// ...
}
}
More information about the Digitalmars-d
mailing list