Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it acceptable to use ThreadPool in a library?

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?

like image 583
Letterman Avatar asked Oct 15 '22 13:10

Letterman


2 Answers

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.

like image 133
Dodd Avatar answered Oct 20 '22 16:10

Dodd


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.

like image 41
Mitch Wheat Avatar answered Oct 20 '22 16:10

Mitch Wheat