SCTP Discussions

Text archives Help


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


Chronological Thread 
  • From: Thomas Dreibholz <dreibh AT iem.uni-due.de>
  • To: "Julio Kriger" <juliokriger AT gmail.com>
  • Cc: discussion AT sctp.de
  • Subject: Re: [SCTP-Discussion] a weird bug (segmentation fault)
  • Date: Thu Jun 1 10:32:11 2006
  • List-id: SCTP Discussions <discussion.sctp.de>

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
=======================================================================

Attachment: pgpCykMdFdup_.pgp
Description: PGP signature




Archive powered by MHonArc 2.6.19+.

Top of page