std.experimental.logger formal review round 3

Martin Nowak via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 29 11:17:46 PST 2014


On 11/29/2014 05:25 PM, Robert burner Schadek wrote:
>
> Yes, there is a lock free, thread local indirection now. That can be
> used to build a lock free, thread local logger.
>
> p.s. You should have taken the phun

I commented on the relevant commit.
https://github.com/burner/phobos/commit/8a3aad5df5218bd995d4679f9b59a59909969b52#diff-59d32a64bcbd4492ff85f10091d73f5fR289

Let me propose a light-weight alternative solution.

```d
abstract class Logger
{
     Object.Monitor mutex;

     this()
     {
         this.mutex = createMutex();
     }

     Object.Monitor createMutex()
     {
         import core.sync.mutex;
         return new Mutex;
     }
}
```

This allows people to override the mutex with whatever fits their bill, 
e.g. one that supports fiber suspension. Especially they can do this.

Object.Monitor createMutex()
{
     static class NoLock : Object.Monitor
     {
         void lock() nothrow {}
         void unlock() nothrow {}
     }
     return new NoLock;
}



More information about the Digitalmars-d mailing list