Sign in to follow this  

Terminating plugin thread

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

At the moment I'm programming a plug-in system for some software and am a little confused about a threading issue. Plug-ins can be made by anyone so I can't make any assumptions about them; they could simply loop infinitely and I should be able to deal with it. Now to handle some plug-in functionality I start a new thread which runs a third-party function. My problem is: What if I want to shut down my application while the function is still running? I don't want to just terminate it since it could have allocated system resources, being in the process of doing IO, etc. At the same time I can't just wait for it to finish since I have no reason to believe that it will finish in the near future. I could just wait for some fixed time (say 5 seconds) and then terminate it if it isn't done yet, but there are legitimate situations where the function takes about a day before finishing (waiting for external events). My initial thought was to have a call-back that tells the plug-in that we're terminating now and that it should have returned from all its functions in x seconds. If it doesn't then it will be terminated. I just don't like the idea of this since if x is too large the user will be annoyed and if x is too small I'll risk that some real plug-ins won't get to finish. At the same time it gives the plug-in programmers yet another responsibility. So can anyone think of a better way to handle this?

Share this post


Link to post
Share on other sites
Why should the plugin get to decide when to quit, instead of the user deciding? If I quit Photoshop with a Gaussian blur running, chances are I don't care about the result of the gaussian blur anyway.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Why should the plugin get to decide when to quit, instead of the user deciding? If I quit Photoshop with a Gaussian blur running, chances are I don't care about the result of the gaussian blur anyway.


Because the plugin may have acquired system resources, so we may end up with resource leaks if we don't let it release resources. It may also be in the process of doing file IO so we could end up with corrupted files because it didn't finished writing.

EDIT: I should perhaps add that these plugins could do stuff like simple source control or automatic backup, so access to the file system, network and some OS resources are required.

Share this post


Link to post
Share on other sites
To remove the user annoyance factor, it's easy enough to half-close by hiding the window, and freeing any resources that aren't being used by plugins. I believe uTorrent does something like this.

Share this post


Link to post
Share on other sites
You don't have to run a loop inside the plugin. Have a different thread inside your application that does the looping, calling in to the plugin each time around.

If your app wants to quit, shut down the loop (which is easy to do now) and call your plugin's clean-up function.

Share this post


Link to post
Share on other sites

This topic is 3720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this