On Sat, Feb 29, 2020 at 9:13 PM Brian Candler <b.cand...@pobox.com> wrote: > > I don't quite follow. If two threads are fighting to use the target fd, then > that's just a race anyway.
One case is when you have full control of the FD namespace, then you can rely on your own synchronization and do whatever you want, but that seems very hard to me in Go (you would have to be aware of every FD creation from any package). The other case is when both oldfd and newfd are open and you control them (or at least you are 100% sure that they will not be closed by other goroutines). Then you can dup2 safely, thanks to the atomicity guarantee. But if a failed dup2 closes newfd without replacing it, then you lose control of newfd (which becomes reusable) and there's no way to retry the operation safely. See my reply to Ian for more details: https://groups.google.com/d/msg/golang-nuts/1AbvThUg3YE/phVzNNvoAAAJ -- 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/CAEvMKD-_BcYvVz%3DNiKpODzTUp4CJbCQ9svpa%3DgoY5HLJfJY9Zw%40mail.gmail.com.