Problems with Mutex
Damian via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Oct 26 16:08:57 PDT 2014
On Sunday, 26 October 2014 at 22:53:09 UTC, Neven wrote:
> On Sunday, 26 October 2014 at 22:21:17 UTC, Damian wrote:
>> On Sunday, 26 October 2014 at 22:14:25 UTC, Neven wrote:
>>> I'm trying to use Mutex from core.sync.mutex; but when I try
>>> to initialize it at compile time this error pops up:
>>>
>>> Error: constructor core.sync.mutex.Mutex.this
>>> core.sync.mutex.Mutex cannot be constructed at compile time,
>>> because the constructor has no available source code
>>>
>>> So I try to initialize it at run time but whenever I use that
>>> mutex in code (via synchronized blocks) I get segmetation
>>> faults (SIGSEGV).
>>>
>>> Code here: http://pastebin.com/Z8Yj2kwY
>>
>> Try
>> __gshared Mutex mutex;
>
> Thanks, that works now; but why?
>
> Why cannot I globally have auto mutex = new Mutex? And why it
> works now when I put __gshared?
Globally you can use:
Mutex mutex;
static this()
{
mutex = new Mutex();
}
More information about the Digitalmars-d-learn
mailing list