There seems to be a conflict between these two statements:
>  should output every line that contains a search word "test" to STDOUT. 
and
>  If one goroutine finds it I can stop the other 7 from working. 

If it is supposed to output EVERY line containing test, what is the logic 
that says you can stop the other goroutines? Is this because you have done 
something ahead of time that separates the input into lines, and so you 
know all the goroutines are operating on the same line? 

It looks, frankly, more like this is code to 'repeat STDIN on STDOUT if 
test is present anywhere in STDIN,' with no cognizance of lines at all.

As long as that is what you are intending to do, rather than the described 
task, then you don't need to worry about stopping the other goroutines at 
all!

"Program execution begins by initializing the main package and then 
invoking the function main. When that function invocation returns, the 
program exits. It does not wait for other (non-main) goroutines to 
complete." -- https://go.dev/ref/spec#Program_execution

Simply exiting from your main when you have completed your read from STDIN 
and your write to STDOUT upon any of the goroutines returning a 
confirmation will end the program, whether other goroutines are still alive 
or not.

Howard


-- 
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/6982a8fd-88a5-4400-87b5-8b0c182000cen%40googlegroups.com.

Reply via email to