I have an application that needs to run in SCTP environment, I have a question in sharing the connection among multiple threads for packet receiving only, I've tried with the sctp_sendmsg and it worked without even locking the threads (is that been taking care of by the OS, in other words, is it thread safe to do that). I've tested many cases with the send and I can't see them out of sync.

Anyway, back to the receiving, is it possible to create multiple threads and send each thread the sctp descriptor to start receiving messages? Do I need a lock here or is it ok without lock?

I'm using C in linux.

1 Answer 1


So I created this quick test program which creates a UDP socket and then runs 2 reader threads and 1 writer thread, all using the same socket. I used nc at the other end to make sure it was working. It's not SCTP but it's BSD sockets, with which SCTP is mostly compatible and on which the enhanced SCTP api is based, so I would expect the behavior to be the same.

It behaves rather well - the sending thread doesn't block at all, and the two receiving threads receive each successive packets in an alternating sequence.

I wouldn't be surprised to see sendmsg() work without issue, but if you are using SCTP in stream mode and sending buffers bigger than the MTU this may not remain true.

But this is linux, I can't make any guarantees about how other OSes would behave.

  • Nice touch to provide some accompanying code on GitHub. Thanks. Sep 28, 2012 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.