is it acceptable to use ThreadPool
in a library?
because that obviously might cause some unpleasant problems if the user of your library is using ThreadPool
as well (due to ThreadPool
being a static class of course)..
what's the convention?
is it acceptable to use ThreadPool
in a library?
because that obviously might cause some unpleasant problems if the user of your library is using ThreadPool
as well (due to ThreadPool
being a static class of course)..
what's the convention?
Yes.
As long as it's well documented, and you provide methods to allow the user of the library to control the threadpool, such as min/max threads and maybe the option to not use a threadpool at all.
You should also make it very clear which exposed parts of your library are threadsafe and which are not.
Yes.I think it is appropriate to make use of the ThreadPool in library code. Even if the user may use ThreadPool outside, ThreadPool is still good enough to tune itself.
On the other hand, as a library developer, you should provide flexibility: user may choose to use ThreadPool, a specific thread(s), or even a 3rd party thread pool implementation.
ThreadPool is designed to be used by multiple components simultaneously. So it in itself presents no particular problem if used from your particular library.
What can be a problem is threading behavior in general in your library. It must be clearly documented what the threading semantics of your library are. How these threads are created and used should should be an implementation detail. The ThreadPool itself shouldn't present a problem unless one of it's inherent properties (COM apartment affinity, inability to cancel threads, etc ...) presents a problem for your API or consumers.