<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 22, 2010, at 12:29 PM, Vinu Rajashekhar wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Wed, Jun 23, 2010 at 12:34 AM, Eric Norum <span dir="ltr"><<a href="mailto:wenorum@lbl.gov">wenorum@lbl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><br><div><div class="im"><div>On Jun 22, 2010, at 10:49 AM, Vinu Rajashekhar wrote:</div><br><blockquote type="cite"><div class="gmail_quote">On Tue, Jun 22, 2010 at 10:44 PM, Eric Norum <span dir="ltr"><<a href="mailto:wenorum@lbl.gov" target="_blank">wenorum@lbl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Why not just use the message queues that RTEMS provides?<div>It seems like a lot of extra work to go through the network stack for this.</div><div><div><div></div><div><br></div>
</div></div></div></blockquote><div>I am not working on C code directly. I am a student currently working</div><div>on the GSoC project of porting gccgo, the gcc frontend to Go into RTEMS.</div><div><br></div><div>The problem is with a network library component of Go. The code is in Go. This </div>
<div>part of the library provides functionality for handling nonblocking sockets efficiently. </div><div>They basically put all the nonblocking sockets into a set, and poll the set to see if </div><div>any one is ready. In linux, they used epoll, but since RTEMS doesn't have it, we </div>
<div>have to use select.</div><div><br></div><div>As part of this support we need to wakeup select when we have to add a new socket</div><div>into the set. So what they used is a pipe, and the read end of the pipe would go into</div>
<div>the set of fds, that epoll/select is polling on. So if we want to wakeup select, we can</div><div>just write something into the pipe. The problem here in RTEMS is, we can't use pipes,</div><div>because select can't wait on them. So we thought of using sockets, that is when the original</div>
<div>doubt of using the same socket for writing in multiple threads came up.</div><div><br></div><div>So I hope you are clear on the context in which this problem came up ?</div><div><br></div><div>So, if writing into the same socket from different threads is not a problem in waking up</div>
<div>select, then I can safely use that. I don't care about the data transferred using the socket.</div><div>Are there better solutions than this ? </div></div></blockquote><div><br></div></div>If you want to retain as much of the existing code in the project then this sounds reasonable.</div>
</div></blockquote><div><br></div><div>Yes, that is the aim ofcourse.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word">
<div>I would suggest that you add a global mutex and obtain it just before the write and release it just after. Then you can be sure that you don't have multiple threads attempting to write at the same time.</div><div>
<div></div><div class="h5"><div><br></div></div></div></div></blockquote><div> </div><div>Well, as I said, we do not care if that happens, if select wakes up because of any one of those</div><div>writes. </div></div></blockquote>I'm not 100% sure that two tasks writing to the same socket descriptor at the same time is safe.</div><div>The underlying sendmsg routine that all the various transmit functions (write, send, sendto) call does take the network semaphore and is thus fine to call from multiple threads at the same time, but I've not looked through the paths that write() takes to get to sendmsg to ensure that all that code is thread-safe.</div><div><br><blockquote type="cite"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><div><div class="h5"><div><blockquote type="cite"><div class="gmail_quote"><div><br></div><div>I was asking about socketpairs() because, if it is possible, I can add that function,</div>
<div>into RTEMS, as part of my work.</div><div><br></div></div></blockquote></div></div></div></div></blockquote><div>I was hoping to get some answer on this, because implementing this using socketpair(), would</div><div>
be a much better option. </div></div></blockquote><div><br></div>I don't recall why I left socketpair out when I ported the FreeBSD network stack to RTEMS. Maybe it would not be too hard to add it, but I make no guarantees about this.</div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div>-- <br>Eric Norum<br><a href="mailto:wenorum@lbl.gov">wenorum@lbl.gov</a></div></span>
</div>
<br></body></html>