Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:08:38+00:00 2026-06-13T10:08:38+00:00

I have the following minimal example that bails out after the first command line

  • 0

I have the following minimal example that bails out after the first command line input due to deadlock:

package main     

import "fmt"     
import "os"     

func main() {     
    channel1 := make(chan string)     

    go func() {     
        var str string     
        for {              
            fmt.Fscanln(os.Stdin, &str)     
            channel1 <- str                
        }                      
    }()      

    for {     
        select {     
        case str := <-channel1:     
            fmt.Printf("Channel1 said: %v\n", str)     
        }                                             
    }             
}  

I would have expected this to simply just take user input and echo it over and over again. Also, I did notice that if I add a second channel and a second go routine that it doesn’t have any deadlock issues. So why does this deadlock?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:08:39+00:00Added an answer on June 13, 2026 at 10:08 am

    Cannot reproduce the problem.

    jnml@fsc-r630:~/src/tmp/SO/13015469$ cat main.go 
    package main
    
    import (
        "fmt"
        "os"
    )
    
    func main() {
        channel1 := make(chan string)
    
        go func() {
            var str string
            for {
                fmt.Fscanln(os.Stdin, &str)
                channel1 <- str
            }
        }()
    
        for {
            select {
            case str := <-channel1:
                fmt.Printf("Channel1 said: %v\n", str)
            }
        }
    }
    jnml@fsc-r630:~/src/tmp/SO/13015469$ go run main.go
    foo
    Channel1 said: foo
    bar
    Channel1 said: bar
    baz
    Channel1 said: baz
    ^Cjnml@fsc-r630:~/src/tmp/SO/13015469$ go build main.go && ./main 
    foo
    Channel1 said: foo
    bar
    Channel1 said: bar
    baz
    Channel1 said: baz
    ^Cjnml@fsc-r630:~/src/tmp/SO/13015469$ go version
    go version go1.0.3
    jnml@fsc-r630:~/src/tmp/SO/13015469$ uname -a
    Linux fsc-r630 3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
    jnml@fsc-r630:~/src/tmp/SO/13015469$ 
    

    What’s your Go version, OS & architecture?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following minimal example code in R: data.time = c(1, 4, 8,
I have following script that executes all the .reg files in the current directory.
In the following minimal example, I create 1-point scatter plot and later change color
First off I apologize if there is another post out there that answers this,
Take the following minimal example: import abc class FooClass(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def
I have following JS code (stripped to minimal size where problem still exists) <html>
I have an application in web2py. To create the command line interface of the
I have the following minmal example of a thread pool made with boost::asio. #include
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.