-
-
Notifications
You must be signed in to change notification settings - Fork 370
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
Unify critical session running in hls #4256
Conversation
@@ -0,0 +1,67 @@ | |||
module Development.IDE.Core.Thread |
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.
I think a more typical name for something like this would be a "work queue" or "job queue".
-- Return ContT to run the action | ||
runWithThread :: ThreadRun input workerResource resource arg -> input -> ContT () IO (resource, TQueue arg) | ||
runWithThread ThreadRun{..} ip = ContT $ \f -> do | ||
tRunWithResource ip $ \w r -> do |
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.
I guess this kind of looks like two separate things to me:
- A domain-specific
withResource
which creates the resource and passes it to a continuation. - A standard "worker queue"
My instinct is that we could focus on defining the worker queue, and just leave the creation of the resource, where necessary, to the call site. Indeed, many of the call sites don't create a resource at all! I think we could then quite naturally write:
withMyResource $ \resource -> withWorkerQueue (\arg -> doSomething resource arg) $ \queue -> ...
or 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.
Make sense, let's implement withWorkerQueue
instead to see if that would make better sense
Co-authored-by: Michael Peyton Jones <[email protected]>
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.
This looks better, makes sense to me.
I do wonder: if we are using blockRunInThread
, then it looks like it's pretty much identical to having a resource that's guarded by a lock, and then having the waiting threads block on acquiring the lock. If we put work into the queue and the move on so it can be executed asynchronously, then it is different. But if we immediately block and wait then there's no real effect of it happening in another thread!
Co-authored-by: Michael Peyton Jones <[email protected]>
Co-authored-by: Michael Peyton Jones <[email protected]>
yes, with a bit different, enqueued actions would not be cancelled even if the thread start it is cancelled. It reminds me of something, we might probably want to limit some of the queue size to 1, so the waiting to enqueue action can be cancelled when we are doing shakeRestart. Then less likely a duplication actions would be run for the sessionLoadQueue |
see #4251
What's done
Development.IDE.Core.Thread
to provide common api to run a woker threadrunWithDb
using theDevelopment.IDE.Core.Thread
Development.IDE.Core.Thread
The above modification ensure the shutdown handler can cancel the session loading and session restart. And hence we would have a more correct shutdown behaviour. Potentially make the test less likely to hang.