[swift-evolution] What're the Swift team's thoughts on Go's concurrency?

Dan Stenmark daniel.j.stenmark at gmail.com
Thu Aug 11 01:10:17 CDT 2016


> On Aug 10, 2016, at 10:24 PM, Chris Lattner <clattner at apple.com> wrote:
> 
> Hi Dan,
> 
> There are many folks interested in concurrency topics related to this, but we need to stay focused on finishing Swift 3 and then moving on to Swift 4 stage 1 goals.  As that work is cresting, we’ll start discussions of concurrency, and may even be so bold as to start a new mailing list dedicated to the topic, since it is such a wide reaching topic.
> 
> Until we get to that point, please resist the urge to jump ahead :-)
> 
> -Chris

Chris, many apologies if this came across the wrong way!  As I attempted to explain in the opening email, I'm inquiring for purely academic reasons and to better my understanding of concurrency as part of language design in general, not to pitch anything for Swift.  In retrospect, perhaps -users would've been a better fit for this question rather than -evolution.


> On Aug 9, 2016, at 1:59 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> On Aug 9, 2016, at 1:28 PM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> The Rust language used to use a green thread model like Go (actually it exposed a configurable threading interface so you could choose green threads or OS threads). It also used segmented stacks like Go did. Over time, Rust ended up dropping the segmented stacks because it significantly complicated FFI without providing much, if any, benefit (and IIRC Go followed suite and dropped segmented stacks somewhere around version 1.5), and then a little while later Rust dropped green threads entirely. If you can find them, there are lots of discussions of the pros and cons that were documented during this process (on mailing lists, in IRC, possibly on Discourse, there's probably at least one post about it in the Rust subreddit, etc). But ultimately, it was determined that keeping this ability significantly complicated the Rust runtime and it provided almost no benefit. The OS is already really good at scheduling threads, and there's no memory savings without segmented stacks (though the OS will map virtual pages for the stack and only allocate the backing physical pages as the memory is touched, so even if you have a 2MB stack, a new thread will only actually allocate something like 8kb). And there are some pretty big downsides to green threads, such as the fact that it significantly complicates the runtime since all I/O everywhere has to be nonblocking and it has to be transparent to the code, and FFI ends up as a major problem (even without segmented stacks), because you have no idea if an FFI call will block. Green threading libraries end up having to allocate extra OS threads just to continue servicing the green threads when the existing threads are potentially blocked in FFI.
>> 
>> So ultimately, green threads really only make sense when you control the entire ecosystem, so you can ensure the whole stack is compatible with green threads and won't ever issue blocking calls, and even there there's not much benefit and there's a lot of complexity involved.
> 
> In addition to FFI, there's also no way for memory-mapped IO to be non-blocking (a page fault can only be handled by the kernel, after all).

This right here is what I was looking for.  Thanks, guys!

Dan


More information about the swift-evolution mailing list