liamzdenek / go-pthreads

Lightweight binding of pthreads to Google Go
BSD 2-Clause "Simplified" License
36 stars 8 forks source link

Callbacks can now accept an argument of the interface type. #3

Closed LukeB42 closed 8 years ago

liamzdenek commented 8 years ago

What's the use case for this change?

Currently, variables can be passed through scope capturing, eg:

arg := "World"
thread := pthread.Create(func() {
    fmt.Printf("Hello, %s\n", arg);
});
LukeB42 commented 8 years ago

Prevents leaving client connections lying around in the calling goroutine, they can just be sent directly to Create.

Makes the behavior of changing the value of arg from your example readily apparent.

liamzdenek commented 8 years ago

Closed as Wont Fix. This change breaks reverse-compatibility for a project that has been stable for several years. It's possible to make this change without breaking reverse-compat, but I don't know what problem this could solve, or why scope capturing is insufficient. Unless there is a good reason, this change belongs in a fork.

(As an aside, this change was performed dangerously. Using two channels to transfer the interface{} argument means that they could become out of sync, and the wrong argument could be matched with the wrong function, particularly if many threads are started concurrently)

LukeB42 commented 8 years ago

OK. Glad this is still maintained. Cheers Liam.