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 8599005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:17:38+00:00 2026-06-12T01:17:38+00:00

http://play.golang.org/p/r92-KtQEGl I am trying to execute this code. It throws a deadlock error. What

  • 0

http://play.golang.org/p/r92-KtQEGl

I am trying to execute this code. It throws a deadlock error.

What am I missing?

package main

import "tour/tree"
import "fmt"

// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int){
    var temp chan int
    ch <- t.Value
    if t.Left!=nil{go Walk(t.Left,temp)}
    if t.Right!=nil{go Walk(t.Right,temp)}
    for i := range temp{
        ch <- i
    }
    close(ch)
}

// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool
  • 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-12T01:17:39+00:00Added an answer on June 12, 2026 at 1:17 am

    You need at least to initialize your channels (if the channel is nil, a range would block forever)

      var temp chan int = make(chan int)
      var ch chan int = make(chan int)
    

    See http://play.golang.org/p/Gh8MZlyd3B (still deadlock but at least display results)

    This version, using two temp channels, doesn’t deadlock: http://play.golang.org/p/KsnmKTgZ83

    package main
    
    import "tour/tree"
    import "fmt"
    
    // Walk walks the tree t sending all values
    // from the tree to the channel ch.
    func Walk(t *tree.Tree, ch chan int) {
        var temp1 chan int = make(chan int)
        var temp2 chan int = make(chan int)
        ch <- t.Value
        if t.Left != nil {
            go Walk(t.Left, temp1)
        }
        if t.Right != nil {
            go Walk(t.Right, temp2)
        }
        if t.Left != nil {
            for i := range temp1 {
                ch <- i
            }
        }
        if t.Right != nil {
            for i := range temp2 {
                ch <- i
            }
        }
        close(ch)
    }
    
    // Same determines whether the trees
    // t1 and t2 contain the same values.
    func Same(t1, t2 *tree.Tree) bool
    
    func main() {
        var ch chan int = make(chan int)
        go Walk(tree.New(1), ch)
        for i := range ch {
            fmt.Println(i)
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wondering is there an equivalent of this feature from play framework http://www.playframework.org/documentation/2.0/JavaAsync Basicly
I'm getting this error when trying to start my play app on Heroku: heroku[web.1]:
i want to play the video of this URL http://www.youtube.com/watch?v=JPUWNcGDyvM&feature=player_embedded where i PAUSE last
I am trying to play video files from http urls in my app. Why
I've carefully cut and pasted from this Rubular window http://rubular.com/r/YH8Qj2EY9j to my code, yet
I am confused by this bit of advice from http://developer.android.com/guide/google/play/billing/billing_integrate.html#billing-signatures To keep your public
I've got the following code (which you can see in play at http://jsfiddle.net/5dbZx/ ).
I'm trying to play around with netcat to learn more about how HTTP works.
I'm trying to play an HTTP live streaming video using a MPMoviePlayerController object, inside
I'm trying to stream a AAC+ shoutcast URL like this one http://live7.avf.ch:8000/ipmusicaacplus32 with flash

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.