-
Notifications
You must be signed in to change notification settings - Fork 284
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
Add getWorkerTask functions #601
Conversation
The unittest blocks check only that the code compiles, but it seems to be what the other tests do. |
You could make a small project in examples/ or tests/ that demonstrates its usage (I like benchmarks best) and runs with the event loop. I think there should be a benchmarks/ subfolder for benchmarks with these tests that compares heavy i/o or heavy compute routines with |
They provide a way to easily create a task in a worker thread and get a handle to it. Signed-off-by: Luca Niccoli <[email protected]>
Thanks! Looks good as far as I can see. The only thing that could be improved is the actual name of the functions - "get" kind of implies that no real action is taken. I don't have a really good idea, though, |
|
Task caller = Task.getThis(); | ||
runWorkerTask_unsafe({ | ||
PrivateTask callee = Task.getThis(); | ||
caller.prioritySend(callee); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You send the Task
as first message with priority, so it will be the first one that is received and
you don't need to use a Typedef, receive((Task t) { result = t; });
should work just as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except if someone else priority-sent something that hasn't yet been received before calling getWorkerTask
. Because it could come from any thread, it would at least be a race condition. Or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Ludwig said, the typedef is necessary because the caller task could receive a Task message at any moment before the callee task is even started. This could happen even without threads: the caller task creates the worker delegate and passes it to runWorkerTask_unsafe, than sits waiting for a Task message; a different task sends (even without priority) a Task message before the worker delegate has been popped from the worker queue; the caller task receives it and mistakes it for the callee task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I forgot that it's receive
not receiveFrom
.
How about |
I'd say |
Would it be preferable to encapsulate the delegate and arguments with a run() method? You could then give it a name like WorkerTask or ThreadLocalTask |
Which delegate do you mean (line number)? Using different types for thread local tasks or worker task doesn't buy much, though, because even thread local task handles can be safely passed to other threads, so that there is no real semantic difference between the two. |
for example
I don't see any practicality in anything vibe currently has, but suppose there would be lazy multi-threading routines, like multi-thread timers or multi-thread queues, having this kind of object handy would help make the API more convenient (I think) |
Can't you just call
|
They provide a way to easily create a task in a worker thread and get a handle to it.
Signed-off-by: Luca Niccoli [email protected]