bshoshany / thread-pool

BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
MIT License
2.21k stars 253 forks source link

[REQ] Request for Adding Hook Interfaces for Custom Code Injection #114

Closed Wzzzx closed 1 year ago

Wzzzx commented 1 year ago

Describe the new feature

I would like to request the addition of hook interfaces. These hooks would allow developers to inject custom code logic at various stages, including thread start, thread end, task start, and task end.

The current thread pool library provides efficient thread management and task scheduling, but it lacks the flexibility to execute custom code logic during important stages of thread and task execution. By introducing hook interfaces, developers can have more control over the execution flow and inject their own code at specific points.

Code example

I suggest implementing these hook interfaces as abstract classes or interfaces, which developers can inherit or implement to provide their own custom code logic. It would be helpful to have clear documentation with guidelines and examples to assist developers in effectively utilizing these interfaces.

Additional information

Include any additional information here.

bshoshany commented 1 year ago

Thanks for the suggestion! However, it seems to me that what you're asking for can be achieved simply by editing the thread pool class itself. The code is open source, and the class is fairly short and straightforward, so if you want to execute any custom code as part of the class's logic, you can simply edit the header file and add it on your own. Alternatively, you can change all the private class members to protected and derive your own class from it.