SCTP Discussions

Text archives Help


Re: [SCTP-Discussion] a weird bug (segmentation fault)


Chronological Thread 
  • From: "Julio Kriger" <juliokriger AT gmail.com>
  • To: "Thomas Dreibholz" <dreibh AT iem.uni-due.de>
  • Cc: discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] a weird bug (segmentation fault)
  • Date: Thu Jun 1 15:02:01 2006
  • Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=nj3H0Wrg4hP0ysxOCHazKoLiN5bHMAwRiTT0p4WN9RweE351cMOjj0Z5pn4Kl283CbvkWg+fteD5FLLUCh5V3cbfrLvBzO83fm8cFIN3injzwkWZYwmt4+sCAcy80czXD8M0vuvENMrki+c8H45xNBYM/mxfu6icSaI6DnsORpE=
  • List-id: SCTP Discussions <discussion.sctp.de>

Hi Thomas!
Thank you very much! for looking at the code. I will modify the code to adjust it to what you say.

For the sake of clarity, correct me if I'm wrong:

1) The must be a single mutex
2) I must not use lock() / unlock() on all the callback function defined in "SCTP_ulpCallbacks" struct.
3) On others functions I must use lock() / unlock() when calling "SCTP_xxxx" function from the library.

Again, my thanks!!!
Best regards,
Julio



On 6/1/06, Thomas Dreibholz <dreibh AT iem.uni-due.de> wrote:
On Wednesday 31 May 2006 23:01, Julio Kriger wrote:
> Hi Thomas!
> I tried to use a single mutex, but I get dead-locks :-((
> Question: if I use sctp_extendedEventLoop, do I have to do "lock, stp_send,
> unlock" ?
> My code is attached. Please be free to comment it as you like.

Your mutex is not recursive, therefore the following happens:
sctp_extendedEventLoop() must be called with the mutex unlocked (as it is in
you code). sctp_extendedEventLoop() itself calls the lock() function when
necessary. When an sctplib event (e.g. data arrive notification) happens, the
lock has already been obtained by sctp_extendedEventLoop(). When your
callback (e.g. DataArriveNotif()) is called, you again call lock(&mutex).
Since the mutex is not recursive, you get a deadlock. Simply removing the
lock() and unlock() calls in your notification implementations should solve
the locking problem.


Yu may also use a recursive mutex, which can be initialized like this:
pthread_mutexattr_t mutexattr;
pthread_mutexattr_init(&mutexattr);
pthread_mutexattr_settype(&mutexattr,PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&Mutex,&mutexattr);
pthread_mutexattr_destroy(&mutexattr);

This will work at least under Linux and FreeBSD; unfortunately, some operating
systems like Darwin do not support such mutexes.


Best regards
--
=======================================================================
Dipl.-Inform. Thomas Dreibholz

University of Essen,                            Room ES210
Inst. for Experimental Mathematics              Ellernstraße 29
Computer Networking Technology Group            D-45326 Essen/Germany
-----------------------------------------------------------------------
E-Mail:     dreibh AT exp-math.uni-essen.de
Homepage:   http://www.exp-math.uni-essen.de/~dreibh
=======================================================================





--
--
Stewie: [After Lois tries to feed Stewie his broccoli "airplane style"] Damn you, Damn the Broccoli, and Damn the Wright Brothers.
----------------------------
Julio Kriger
mailto:juliokriger AT gmail.com



Archive powered by MHonArc 2.6.19+.

Top of page