Re: Go concurrency slides

233 views
Skip to first unread message

John Nagle

unread,
Jun 6, 2013, 1:54:51 PM6/6/13
to golan...@googlegroups.com
On 5/29/2013 10:36 AM, jeid...@gmail.com
wrote:
> Hello,
>
> I've written up three presentations on Go concurrency. These are meant for
> beginning Go users. If anyone has the time to critique, I'd love to hear
> what can be improved. Thanks!

That presents channels as a synchronization mechanism, not a data
transmission mechanism. There's no discussion of shared data and its
problems.

It's also painful to see P and V created out of channels.
That's backwards. Underneath, a channel is two PV semaphores and
a circular buffer.

John Nagle

André Moraes

unread,
Jun 6, 2013, 4:03:34 PM6/6/13
to jeid...@gmail.com, golan...@googlegroups.com
>
> 1. Channels
>
> http://talks.godoc.org/github.com/jeidsath/bootcamp/channels.slide

package main

import (
"fmt"
"time"
)

func sayit(messages chan string) {
for msg := range messages {
fmt.Printf("said: %v\n", msg)
}
}

func main() {
messages := make(chan string)
go sayit(messages)
go sayit(messages)

for i := 0; i < 10; i++ {
if i % 2 == 0 {
messages <- "Hi!"
} else {
messages <- "Hello!"
}
}

time.Sleep(1000)

}

--
André Moraes
http://amoraes.info

Joel Eidsath

unread,
Jun 6, 2013, 6:11:57 PM6/6/13
to golan...@googlegroups.com, na...@animats.com
    That presents channels as a synchronization mechanism, not a data
transmission mechanism. There's no discussion of shared data and its
problems.

Thanks for the response, John. The next slide set that is planned is a discussion of how to share a map across goroutines. I thought that would motivate the sharing/communicating discussion reasonably well.
 
    It's also painful to see P and V created out of channels.
That's backwards.  Underneath, a channel is two PV semaphores and
a circular buffer.

Are you talking about the semaphore example? I took it from Effective Go. I'd be happy to replace it with a better pattern.

Joel Eidsath

unread,
Jun 6, 2013, 6:23:34 PM6/6/13
to golan...@googlegroups.com, jeid...@gmail.com

package main

import (
        "fmt"
        "time"
)

func sayit(messages chan string) {
        for msg := range messages {
                fmt.Printf("said: %v\n", msg)
        }
}

func main() {
        messages := make(chan string)
        go sayit(messages)
        go sayit(messages)
        
        for i := 0; i < 10; i++ {
                if i % 2 == 0 {
                        messages <- "Hi!"
                } else {
                        messages <- "Hello!"
                }
        }

        time.Sleep(1000)

}  
--
André Moraes
http://amoraes.info

Thanks Andre. That looks surprisingly like my first draft for that introductory program! My goals for that slide were to get the reader to consider the two goroutine invocations. The output of Heys versus Hos is semi-random, and I hoped that might make people think about why that would happen without any control structure or weird keywords.
Reply all
Reply to author
Forward
0 new messages