Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question

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.

share|improve this answer
    
Nice touch to provide some accompanying code on GitHub. Thanks. –  DeveloperDon Sep 28 '12 at 2:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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