Code reference:
https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=523-565

* c.writerDescriptor creates the pipe, and a copying function is appended 
to the slice c.goroutine. This slice contains the functions which will be 
started in their own goroutines.
* c.childStdout calls c.writerDescriptor
* c.childStderr reuses the exiting childStdout if Stdout and Stderr are the 
same (and therefore there is still only one function in c.goroutine)
* interfaceEqual implements the check that Jason quoted:
https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=473-480

On Wednesday, 4 October 2023 at 05:58:29 UTC+1 Jason Phillips wrote:

> From the Stdout/Stderr field documentation on the os/exec.Cmd type 
> <https://pkg.go.dev/os/exec#Cmd>:
>
> "If Stdout and Stderr are the same writer, and have a type that can be 
> compared with ==, at most one goroutine at a time will call Write."
>
> On Tuesday, October 3, 2023 at 9:55:16 PM UTC-4 王富民awaw wrote:
>
> exec.CombinedOutput uses the same io.Writer for both stdout and stderr in  
> exec.go 
> - Go (opensource.google) 
> <https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=1003>
>  .
> This io.Writer is written in  exec.go - Go (opensource.google) 
> <https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=717>
>  .
> These two writes happens concurrently in two goroutines in exec.go - Go 
> (opensource.google) 
> <https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/os/exec/exec.go;l=717>
>  .
> As far as I know, bytes.Buffer is not safe to concurrent writes.
> Is this not a race?
>
>

-- 
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/5fd62068-f540-4a89-8fdb-10eaf86b5850n%40googlegroups.com.

Reply via email to