-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
copy() for Tasks #4085
Comments
@JeffBezanson Would like to take a crack at it. |
@JunaidBKirkire go for it! Just make sure that your pull request references this issue by including the (unquoted) string |
Do we really need to deepcopy task local storage or is a copy sufficient? It seems to me like a deepcopy is overkill. |
Shallow copy is probably the right thing.
|
also would need to check whether the task being copied is jl_current_task the user asked for a deep-copy, so it seems like that would mean tls also. otoh, if the user just it's a bit hard to implement this without having an example use case to use as a test |
I doubt anyone has tried exactly the use case of cloning tasks for probabilistic programming in Julia. @zenna has probably done the most wrt prob prog in julia; I know a fair amount about how coroutines are implemented in Julia but not enough to implement this feature myself. Let's move the general discussion of tasks for probprog to the forum and leave this issue specifically about the copy functionality. |
copying here my concerns from #12625 (comment) that I would want to see addressed first. In particular though, I would be very against merging something to close this issue that in any way adds complexity or difficulty to the implementation of the very important gc-optimizations mentioned previously.
to add to that, I also feel that it is disconcerting that the copy / deep-copy behavior is essentially unpredictable. |
The code contained in PR #15078 has been used for a few months in a probabilistic programming library for Julia. The observed behavior of this implementation has been so far stable and predictable in our experiments. As mentioned in PR #15078, this implementation duplicates the target task's stack. So, in principle, any GC optimisations applicable to the target task can be repeated on the copied task's stack. |
Having the code working for a few month in a very limited usage pattern is relatively easy and basically doesn't really mean anything. There's a fundamental difference between having something that kind of works (i.e. works for a single usage pattern) and providing it in the standard library. Just to name a few obvious things that a task cannot do if you want to copy it.
This also kills |
These are valid concerns indeed. However these issues have been met and solved in situations where For example, the first two issues are solvable by avoiding caching self reference in task related code. The 3rd issue is more tricky, but it is easy to add checking in task-switching code to enforce The last issue related to |
Yes, this has all the problem with
I don't think this is practical. It's hard enough to predict when a task switch can happen and we shouldn't make is much harder to write code that is robust against task switch. Getting this to work will involve adding code to deal with this unlikely case that will unnecessarily slow everything else down. Given what you can do by coping a running task should be much cleaner to be implemented as cloning a stateful generator (iterator), I don't think it makes sense to implement this. |
This needs to be implemented in
task.c
. After copying all the fields of thejl_task_t
, the following extra changes are needed:tls
consumers
tojl_nothing
donenotify
tojl_nothing
allocb
a copy ofstkbuf
, which isbufsz
bytesI think there is a chance that will work.
The text was updated successfully, but these errors were encountered: