Philip Martin wrote on Wed, Mar 30, 2011 at 10:33:42 +0100:
> Daniel Shahaf <d.s_at_daniel.shahaf.name> writes:
>
> > Why does svn_io_file_lock2() have a retry loop?
> >
> > The reason given in the code is that some consumer of libsvn_fs wants to run
> > a critical section while holding a lock in each of two FSFS filesystems. In
> > that case, why isn't the fix just to tell the consumer to, when wanting to
> > lock N filesystems, to always lock them in a well-defined order?
>
> First, the knowledge about the locks is entirely within the thread at
> present, each thread has no knowledge of what other threads are doing.
But if the threads are independent, why are you describing the situation
as deadlock? With independent threads, p1t1 and p2t1 should finish
their business and unlock both A and B, independently of anyone else who
may have tried to lock either A or B...
> You would need to introduce some sort of per-process lock handler.
>
> Secondly, from the comment in the code:
>
> Process 1 Process 2
> --------- ---------
> thread 1: get lock in repos A
> thread 1: get lock in repos B
> thread 2: block getting lock in repos A
> thread 2: try to get lock in B *** deadlock ***
>
> when each process takes the first lock it may not know that it will want
> the second lock.
>
Okay, processes that don't know in advance what locking order they
need does sound better.
> --
> Philip
Thanks,
Daniel
Received on 2011-03-30 13:01:30 CEST