Re: Review of gnio, round 1



On Mon, 2009-04-27 at 17:28 -0700, Dave Benson wrote:
> > >In libsoup it's also important because it's thread-safe/non-racy. That
> > >may not be a relevant criterion for GSocket, although the source
> > >returned by g_socket_create_source() could create similar problems; you
> > >need to be certain that any such sources are destroyed before you call
> > >g_socket_close(), or else they could trigger falsely if the fd gets
> > >reused. Delaying close() until finalization makes that easy because then
> > >you can just have the source hold a ref on the socket to ensure that the
> > >fd doesn't get closed.
> 
> Why not just set the FD to -1?
> It'll give bad a EBADF instead of ENOTCONNECTED (or whatever),
> but it seems better...  no flags, i guess it's "racy" but that's
> intrinsic to the circumstance of having one thread writing and another closing.
> (Really, the caller is going to have to have a lock if they want
> multiple threads to write to the same fd)

The race isn't about another thread writing to the socket, but rather a
mainloop source created from the socket, and that puts the fd in the
mainloop, so its not that trivial to "set it to -1".



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]