How could we declare a variable or pointer of lmrtfy::thread_pool
chenscottus opened this issue · 4 comments
How could we declare variable lmrtfy::thread_pool, for example,
in a header h
lmrtfy::::thread_pool pool_var;
//Or
lmrtfy::::thread_pool * pool_ptr;
in a cpp
pool_var = lmrtfy::thread_pool();
lmrtfy:::thread_pool pool
pool_ptr = &pool;
Thanks!
I'm not sure why exactly you want a pointer to it, you might have to explain more. Perhaps you want a reference? For example, if you're passing a lmrtfy::thread_pool
to a function, you could declare it something like
void foo(lmrtfy::thread_pool<>& pool) { ... }
(I believe the <> are necessary when passing an empty-template-list template into a function)
Or perhaps you want it to be global?
For example,
In a head file - myclass.h, I will declare a pool variable:
lmrtfy::thread_pool<> pool_vars;
In a cpp file - myclass.cpp, I will initialize the pool variable when myclass running:
pool_vars = lmrtfy::thread_pool ;
How can I do that?
Thanks!
If it's a global variable, and you are okay with it being initialized at startup and destroyed at exit, an easier way is to put
inline lmrtfy::thread_pool pool_vars;
in your header, you don't need to define it in a separate .cpp file.
If you need to delay initialization or perhaps end it early, you could do something similar:
inline std::unique_ptr<lmrtfy::thread_pool> pool_vars;
Then, when you want to initialize:
pool_vars = std::make_unique<lmrtfy::thread_pool>();
And when you want to destroy it:
pool_vars.reset();
If you don't need it to be global, perhaps a member of a class, just declare it as a member of the class and it will be correctly default initialized in any constructor.
Let me know if you are trying to do something else.
Great! Thanks!