Ping qznc: Re: A little of coordination for Rosettacode

monarch_dodra monarchdodra at gmail.com
Sat Feb 16 02:08:26 PST 2013


On Saturday, 16 February 2013 at 07:58:56 UTC, qznc wrote:
> On Saturday, 16 February 2013 at 06:58:01 UTC, qznc wrote:
>> On Saturday, 16 February 2013 at 02:23:42 UTC, Jos van Uden 
>> wrote:
>>> On 5-2-2013 20:45, Jos van Uden wrote:
>>> 
>>>> By the way, I think 'Qznc' may want to have a look at 'The 
>>>> dining
>>>> philosophers':
>>>>
>>>> http://rosettacode.org/wiki/Dining_philosophers
>>
>> I should find the time to solve it this weekend.
>
> Wow, my kid let me do some hacking right now and it was simpler 
> than expected.
> Posted a solution already.

Hum...

//----
	Mutex[5] forks = new Mutex();
//----

This will allocate a single Mutex, and place the same reference 
in all five entries of forks.

In a word: There is actually only one fork. The philosophers can 
still dine, because a single thread is allowed to lock the same 
resource twice, making the problem trivial. Basically, they are 
dual wielding the fork ;)

The correct line of code should be:
//----
	Mutex[5] forks;
	foreach(ref fork; forks) fork = new Mutex();
//----

Or some variation thereof of course. The code still works with 
this change.

I'm reporting it instead of correcting it directly, so as to 
better explain how and why.


More information about the Digitalmars-d-learn mailing list