Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yielding to a copied task crashes #4080

Closed
sharpobject opened this issue Aug 16, 2013 · 3 comments
Closed

Yielding to a copied task crashes #4080

sharpobject opened this issue Aug 16, 2013 · 3 comments

Comments

@sharpobject
Copy link

julia> consume(Task(()->7))
7

julia> consume(deepcopy(Task(()->7)))
Segmentation fault

I don't know what the right behavior is here. If tasks are not meant to be copied, copying one could return the original or throw an exception.

There are significant use cases for copying tasks, though, so I hope that they are meant to be copied. In that case, the bug is that copied ones do not work.

@JeffBezanson
Copy link
Member

No, tasks are not currently meant to be copied. I think it could be implemented, but the semantics are a bit fiddly. For example, a task waiting for the original task is probably not waiting for the copy. And values referenced from the task's stack should probably not be deep-copied.

Stefan and I kind of disapprove of deep copying in general, but we were not quite able to talk people out of adding it.

@sharpobject
Copy link
Author

These issues are troublesome. In the contexts in which I'm used to being able to copy coroutines, the coroutines are rigidly asymmetric, so the solutions that are enabled by that assumption may not be applicable. I'll look into it a bit more if I have time.

> t = coroutine.create(function()coroutine.clone(t) end)
> print(coroutine.resume(t))
false   attempt to clone uncloneable coroutine
> -- The coroutine cannot be copied while it is running
>
> t = coroutine.create(function()print(coroutine.resume(coroutine.create(function()coroutine.clone(t) end))) end)
> print(coroutine.resume(t))
false   attempt to clone uncloneable coroutine
true
> -- It also cannot be copied while it is waiting on another
>
> t = coroutine.create(function() local t = {0} while true do coroutine.yield(t[1]) t[1] = t[1]+1 end end)
> print(coroutine.resume(t))
true    0
> u = coroutine.clone(t)
> print(coroutine.resume(t))
true    1
> print(coroutine.resume(u))
true    2
> -- It receives a shallow copy of the stack
>
> t = coroutine.create(function() local t = 0 while true do coroutine.yield(t) t = t+1 end end)
> print(coroutine.resume(t))
true    0
> u = coroutine.clone(t)
> print(coroutine.resume(t))
true    1
> print(coroutine.resume(u))
true    1
> -- But certainly not the same exact stack

@pao
Copy link
Member

pao commented Aug 19, 2013

Looks like this should be linked to #4085.

jishnub pushed a commit that referenced this issue Nov 21, 2024
Stdlib: Pkg
URL: https://github.com/JuliaLang/Pkg.jl.git
Stdlib branch: master
Julia branch: master
Old commit: 9f8e11a4c
New commit: 7b759d7f0
Julia version: 1.12.0-DEV
Pkg version: 1.12.0
Bump invoked by: @IanButterworth
Powered by:
[BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl)

Diff:
JuliaLang/Pkg.jl@9f8e11a...7b759d7

```
$ git log --oneline 9f8e11a4c..7b759d7f0
7b759d7f0 Automatically upgrade empty manifest files to v2 format (#4091)
69c6de019 Remove duplicated word "different" (#4088)
87a4a9172 Actually switch to "Resolving Deltas" (#4080)
ef844e32f Update CHANGELOG.md: link to [sources] PR (#4084)
e10883ce5 REPLExt: check for compliant repl mode during repl init (#4067)
```

Co-authored-by: Dilum Aluthge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants