News for hackers. Stuff that matters.
Re:Notes on structured concurrency, or: Go statement conside... by marcus_holmes on Wednesday April 25, 2018 @12:02PM (#16922850)
But this concept does also solve that problem. Maybe more simply.

Rust is renowned for being a total headache with borrowing and lifetimes. Nurseries might be a simpler solution for this.

As you say, a corner case. But a common one...

Re:Notes on structured concurrency, or: Go statement conside... by lilyball on Wednesday April 25, 2018 @02:06PM (#16924300)
Nurseries and lifetimes are orthogonal concepts. In fact, Rust already has a "nursery", except it's generally called a scoped threadpool. They use lifetimes to ensure the threads can reference stuff on the stack without copying it. So a "nursery" is basically just a scoped threadpool with a 'static lifetime.
Re:Notes on structured concurrency, or: Go statement conside... by steveklabnik on Wednesday April 25, 2018 @03:11PM (#16924977)
There is some interesting stuff about this in the /r/programming thread https://www.reddit.com/r/programming/comments/8es8x3/notes_o...
Re:Notes on structured concurrency, or: Go statement conside... by stouset on Wednesday April 25, 2018 @10:21PM (#16928292)
I don’t think there’s any reason a nursery has to have a static lifetime.
Re:Notes on structured concurrency, or: Go statement conside... by eridius on Thursday April 26, 2018 @12:13AM (#16928743)
The description of the nursery is you can pass it around wherever you like. More generally, this concept seems to have been designed in a language without lifetimes. You obviously can have a scoped threadpool without a 'static lifetime, but if you want to pass it around to arbitrary locations then you do.
Re:Notes on structured concurrency, or: Go statement conside... by twic on Thursday April 26, 2018 @08:33AM (#16931232)
I think the whole point of the nursery's design is that you can create and destroy them during the life of your program, and that destroying them forms a barrier where the owner of the nursery waits for its children to finish. Having a nursery with a static lifetime in Rust would therefore be pointless, as it would live until the end of the program.
Re:Notes on structured concurrency, or: Go statement conside... by eridius on Thursday April 26, 2018 @11:50AM (#16932960)
I think you misunderstand. I'm talking about writing something like `ScopedThreadpool<'static>`, which means any external data referenced by the threadpool must have a static lifetime (or rather, it means the ScopedThreadpool cannot reference anything on the stack, because that would prevent you from e.g. returning it to your caller or passing it to another thread). The ScopedThreadpool itself can be created and destroyed whenever.
Re:Notes on structured concurrency, or: Go statement conside... by arghwhat on Thursday April 26, 2018 @10:15AM (#16932055)
I would definitely consider the "nursery" to be a newly created device (threadpool/reactor/...), where the resources used by the functions run in this "nursery" only has a lifetime requirement equal to the nursery.
Re:Notes on structured concurrency, or: Go statement conside... by arghwhat on Wednesday April 25, 2018 @04:17PM (#16925621)
It actually does not solve the problem of lifetimes. It only solves a very isolated instance of it.

For example, if we take the problem of an os.File, some library might store the reference, and use it unexpectedly in a later function call after you called Close. This presents the exact same issue as a goroutine holding it.

(I honestly have no other examples of this issue than files/connections being closed prematurely for Go.)

Re:Notes on structured concurrency, or: Go statement conside... by wybiral on Wednesday April 25, 2018 @08:01PM (#16927602)
I've never encountered a situation in Go where I'm passing file handles around like this.

In practice you'd probably have one goroutine manage the resource and its lifespan then other code would communicate with that goroutine using channels.

Re:Notes on structured concurrency, or: Go statement conside... by arghwhat on Thursday April 26, 2018 @03:48AM (#16929764)
You might pass an os.File or a network connection as an io.Reader or io.Writer to something that might keep it. The GC actually has an extension to sorta have destructors to help with leaking fd's from forgotten os.File's (runtime.SetFinalizer).

However, having coded Go for quite a few years by now, I haven't found it to be an issue at all.