Re: A few remarks about locking



On Tue, Mar 26, 2002 at 09:35:33PM +0100, Pawel Salek wrote:
> 
> One must be *extremely* careful. nested locks must always acquired in 
> same order (see HACKING). Otherwise, it easy to deadlock. Possible 
> scenario: mailbox lock is held by a thread, gdk lock is released. The 
> other thread gets GDK lock and waits for mailbox lock. The first thread 
> tries to get GDK lock back, and we have a deadlock.
> 

in this particular:

libbalsa_mailbox_load_messages(LibBalsaMailbox * mailbox)
....
    if (CLIENT_CONTEXT_CLOSED(mailbox))
	return;

+	gdk_threads_leave();

    LOCK_MAILBOX(mailbox);
    for (msgno = mailbox->messages; mailbox->new_messages > 0; msgno++) {
	cur = CLIENT_CONTEXT(mailbox)->hdrs[msgno];
...
    }
    UNLOCK_MAILBOX(mailbox);

+	gdk_threads_enter();

    if(messages!=NULL){
      gtk_signal_emit(GTK_OBJECT(mailbox),
			libbalsa_mailbox_signals[MESSAGES_NEW], messages);
      g_list_free(messages);
    }


doesn't seem particularly evil

-- 
Carlos Morgado - chbm(at)chbm(dot)nu - http://chbm.nu/ -- gpgkey: 0x1FC57F0A 
http://wwwkeys.pgp.net/ FP:0A27 35D3 C448 3641 0573 6876 2A37 4BB2 1FC5 7F0A
I am Homer of Borg! Prepare to be... OOooo! donuts! 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]