On Saturday, 29 February 2020 12:37:24 UTC, Ian Lance Taylor wrote:
>
> On Sat, Feb 29, 2020 at 12:33 AM Brian Candler <b.ca...@pobox.com 
> <javascript:>> wrote: 
> > 
> > Just to ask the an obvious question: is dup2() idempotent or not? 
>
> dup2 in itself is idempotent.  But I'm not sure that is a useful 
> question.


I think it makes sense in the context of the question "should I repeat 
dup2() if it returns with EINTR?"  If it's idempotent, then it's safe to do 
so.

 

>  The issue is whether some other thread in the same process 
> can open a file at the target file descriptor between calls to dup2.  

To put it another way, dup2 is idempotent, but if you make multiple 
> calls to dup2, the order in which you make those calls matters. 


I don't quite follow.  If two threads are fighting to use the target fd, 
then that's just a race anyway.

fds are a global resource; if one thread is doing (say) dup2(3,10), then it 
must already be sure that fd 10 is available globally, i.e. it won't be 
stomping on any other thread using fd 10.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b6df168f-dd7c-4a37-a52e-e4cdc2fb29cb%40googlegroups.com.

Reply via email to