DMD 1.022 and 2.005 releases - what's wrong with threading?

downs default_357-line at yahoo.de
Sun Oct 7 00:09:19 PDT 2007


David Brown wrote:
> This is certainly not what I would hope to ever find in a normal piece of
> threading code.  Let's pretend I have condition variables (.NET style), and
> see what it looks like:
> 
>   void put(T t)
>   {
>     synchronized (this) {
>       buffer ~= t;
>       conditionSignal (this);
>     }
>   }
> 
>   void get(T t)
>   {
>     synchronized (this) {
>       while (buffer.length == 0)
>         conditionWait (this);
>       auto res=buffer[0];
>       buffer = buffer[1..$];
>       return res;
>     }
>   }
> 

Your implementation has, as far as I can tell, a fatal flaw. If
conditionWait is called before put, put's synchronized(this) will block
indefinitely.
Am I missing something here?
 --downs, confused



More information about the Digitalmars-d mailing list