[Gtk-sharp-list] Creating critical section for unhandled exception handler

Styne jason.steenstrapickens at orionhealth.com
Thu May 20 21:16:58 EDT 2010


Hi,

I followed the steps at  http://www.mono-project.com/GtkSharpNewInVersion2x
http://www.mono-project.com/GtkSharpNewInVersion2x  to add an event handler
for unhandled exceptions so that I could display it in a dialog and then
close the application correctly.

Then I added a TreeView to my window and had a bug in my TreeCellDataFunc
delegate which would always raise an exception when the tree was trying to
display its contents.

The problem was that now I was getting multiple dialogs. To avoid this I
made a critical section around the code which displays the dialog and then
blocks until it a response event or it is destroyed. I was locking on a
private instance variable of the Window.

I expected to only get one dialog but I was surprised to get just as many as
before.

I then added a counter which incremented at the start of the critical
section and decremented at the end. This counter should always be 0 when
there is no thread in the critical section and 1 when there is. The strange
thing was that this counter was getting >1 so obviously the lock is not
behaving as I expected.

I then printed out the ManagedThreadId property of the
System.Threading.Thread.CurrentThread and found that it was the same thread
entering the critical section multiple times!

I'm confident that I have proven:
1) A thread that enters the critical section will block until the dialog is
closed (Dialog.Run() blocks, plus the counter doesn't decrement until the
dialog is closed)
2) There are multiple threads in the same critical section at the same time
(multiple dialogs, plus counter > 1)
3) It is the same thread that is re-entering the critical section without
ever leaving it (same ManagedThreadId which is guaranteed to be unique for
each thread)

Is this a bug or am I doing something wrong?

Let me know if you need to see the source.
-- 
View this message in context: http://mono.1490590.n4.nabble.com/Creating-critical-section-for-unhandled-exception-handler-tp2225522p2225522.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.


More information about the Gtk-sharp-list mailing list