cretindesalpes
29th January 2012, 22:13
I'm currently writing a small multi-threading library mainly for Avisynth plug-in development (but not restricted to). I have a few questions and would like to read advices form people here before going further.
The library works as a thread pool, meaning that you just have to push parallel tasks into the queue and wait for their completion.
Now I would like to make all the plug-ins implementing the library share a single pool of threads per process, in order to reduce the resource load, particularly when using the MT modes. So instead of having 50+ threads trying to access more or less simultaneously the computer resources, the plug-ins would share the N threads available from the pool (more the original MT threads). This would help to reduce the number of MT threads in order to reach a full CPU load with a single Avisynth process.
The main drawback is that the common code would have to be in a shared dll, installed in the System32/SysWOW64 folder. This probably sounds a bit complicated for most users (remember the libfftw*.dll issues?) And this is one more dll in the Avisynth plugin folder if you want the possibility to set the global number of threads from the script. So I'm wondering if the shared stuff is really worth it. Or is there any alternative for sharing the thread pool?
At the moment, the header looks like this:
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
namespace avstp { class TaskDispatcher; }
typedef avstp::TaskDispatcher avstp_TaskDispatcher;
#else
typedef struct avstp_TaskDispatcher avstp_TaskDispatcher;
#endif // __cplusplus
typedef void (__cdecl *avstp_TaskPtr) (avstp_TaskDispatcher *td_ptr, void *user_data_ptr);
enum
{
avstp_Err_OK = 0,
avstp_Err_EXCEPTION = -999,
avstp_Err_INVALID_ARG
};
enum { avstp_INTERFACE_VERSION = 1 };
__declspec (dllexport) int __stdcall avstp_get_interface_version ();
__declspec (dllexport) avstp_TaskDispatcher * __stdcall avstp_create_dispatcher ();
__declspec (dllexport) void __stdcall avstp_destroy_dispatcher (avstp_TaskDispatcher *td_ptr);
__declspec (dllexport) int __stdcall avstp_get_nbr_threads ();
__declspec (dllexport) int __stdcall avstp_enqueue_task (avstp_TaskDispatcher *td_ptr, avstp_TaskPtr task_ptr, void *user_data_ptr);
__declspec (dllexport) int __stdcall avstp_wait_completion (avstp_TaskDispatcher *td_ptr);
#ifdef __cplusplus
}
#endif
Any comment appreciated.
The library works as a thread pool, meaning that you just have to push parallel tasks into the queue and wait for their completion.
Now I would like to make all the plug-ins implementing the library share a single pool of threads per process, in order to reduce the resource load, particularly when using the MT modes. So instead of having 50+ threads trying to access more or less simultaneously the computer resources, the plug-ins would share the N threads available from the pool (more the original MT threads). This would help to reduce the number of MT threads in order to reach a full CPU load with a single Avisynth process.
The main drawback is that the common code would have to be in a shared dll, installed in the System32/SysWOW64 folder. This probably sounds a bit complicated for most users (remember the libfftw*.dll issues?) And this is one more dll in the Avisynth plugin folder if you want the possibility to set the global number of threads from the script. So I'm wondering if the shared stuff is really worth it. Or is there any alternative for sharing the thread pool?
At the moment, the header looks like this:
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef __cplusplus
namespace avstp { class TaskDispatcher; }
typedef avstp::TaskDispatcher avstp_TaskDispatcher;
#else
typedef struct avstp_TaskDispatcher avstp_TaskDispatcher;
#endif // __cplusplus
typedef void (__cdecl *avstp_TaskPtr) (avstp_TaskDispatcher *td_ptr, void *user_data_ptr);
enum
{
avstp_Err_OK = 0,
avstp_Err_EXCEPTION = -999,
avstp_Err_INVALID_ARG
};
enum { avstp_INTERFACE_VERSION = 1 };
__declspec (dllexport) int __stdcall avstp_get_interface_version ();
__declspec (dllexport) avstp_TaskDispatcher * __stdcall avstp_create_dispatcher ();
__declspec (dllexport) void __stdcall avstp_destroy_dispatcher (avstp_TaskDispatcher *td_ptr);
__declspec (dllexport) int __stdcall avstp_get_nbr_threads ();
__declspec (dllexport) int __stdcall avstp_enqueue_task (avstp_TaskDispatcher *td_ptr, avstp_TaskPtr task_ptr, void *user_data_ptr);
__declspec (dllexport) int __stdcall avstp_wait_completion (avstp_TaskDispatcher *td_ptr);
#ifdef __cplusplus
}
#endif
Any comment appreciated.