lwip-devel
[Top][All Lists]
Advanced

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

[lwip-devel] [bug #23408] Deadlock on sys_mbox_post sys_mbox_fetch


From: Vadim G Melihow
Subject: [lwip-devel] [bug #23408] Deadlock on sys_mbox_post sys_mbox_fetch
Date: Wed, 28 May 2008 17:08:54 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.8.1.4) Gecko/20060911 SUSE/2.0.0.4-1.2 Firefox/2.0.0.4

Follow-up Comment #6, bug #23408 (project lwip):

Sorry. A little tired.  This is corrected post.

u32_t
sys_arch_mbox_fetch(struct sys_mbox *mbox, void **msg, u32_t timeout)
{
  u32_t time = 0;

  /* The mutex lock is quick so we don't bother with the timeout
     stuff here. */
  sys_arch_sem_wait(mbox->mutex, 0);

  while (mbox->first == mbox->last) {
    sys_sem_signal(mbox->mutex); <-------- 1st operation 

    /* We block while waiting for a mail to arrive in the mailbox. We
       must be prepared to timeout. */
    if (timeout != 0) {
      time = sys_arch_sem_wait(mbox->mail, timeout); 

      if (time == SYS_ARCH_TIMEOUT) {
        return SYS_ARCH_TIMEOUT;
      }
    } else {
/*
I want to say that between these two operations (1st and 2nd) possibly switch
CPU context to writer thread and filling the whole messagebox, followed by
blocking semaphore mbox->mail.

As a result we get a deadlock.

When a large amount of msgbox elements (SYS_MBOX_SIZE) that is likely to
happen is small. 

*/

      sys_arch_sem_wait(mbox->mail, 0); <-------- 2nd operation 
    }
    sys_arch_sem_wait(mbox->mutex, 0);
  }

  if (msg != NULL) {
    LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %pn", (void *)mbox,
*msg));
    *msg = mbox->msgs[mbox->first % SYS_MBOX_SIZE];
  }
  else{
    LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msgn", (void
*)mbox));
  }

  mbox->first++;

  if (mbox->wait_send) {
    sys_sem_signal(mbox->mail);
  }

  sys_sem_signal(mbox->mutex);

  return time;
}





    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?23408>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]