Re: dealing with deadlocks in jedit - avoid them
Matthieu Casanova <chocolat.mou <at> gmail.com>
2012-06-01 08:18:35 GMT
So, let's continue this conversation:
The rule that everyone agreed is (correct me if you don't agree) :
only EDT can aquire a write lock
invokeAndWait cannot be called when the current thread has a lock (read lock since the current thread is not EDT)
But that's not enough because of your previous example
1. T1 acquires read lock for A
2. T2 enters EDT and acquires write lock for B
3. T1 wants read lock for B, T2 wants write lock for A
In that case we could add another rule: only one write lock can be aquired at the same time. I think it would solve that case.
Would it be acceptable ?
Another thing: I think that all those rules do not apply to temporary buffers, since those buffers are not in the buffer list and not displayable, they are not shared by different threads.
2012/5/30 Matthieu Casanova
<chocolat.mou <at> gmail.com>
Hi, I think I agree, a thread must not enter EDT when having a lock, and write lock must only be took in EDT thread.Maybe to help debugging a new constant like Debug.BUFFER_WRITE_LOCK_DEBUG could be added, and when activated the thread would be tested in JEditBuffer.writeLock(), and if it is not EDT an exception is thrown (like Substance look & feel does when you change the UI in the wrong thread)
2012/5/30 Jarek Czekalski
<jarekczek <at> poczta.onet.pl>
So I was wrong in 2 things, thank you Matthieu and Kazutoshi for
correcting me. This however doesn't change the general idea, because the
deadlock is still possible regarding buffer locks.
1. T1 acquires read lock for A
2. T2 enters EDT and acquires write lock for B
3. T1 wants read lock for B, T2 wants write lock for A
We must have a rule to make this situation forbidden. Sorting of buffers
cuts it. I think what Przemek suggested is quite right, but it will be
simpler using AtomicInteger.
Przemek, your understanding of getting locks after entering EDT is same
as mine. As Kazutoshi pointed, it is already documented that insert,
which contains writeLock, must be called from EDT. So it only confirms
that such a rule should be published: a thread must not enter EDT, if it
possesses a buffer lock.
If there are no objections, I'll assemble these rules into wiki and javadoc.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
--
--
-----------------------------------------------
jEdit Developers' List
jEdit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-devel