mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
Merge pull request #2943 from MartinNowak/useInitOnce
use initOnce for lazy shared initialization
This commit is contained in:
commit
bcedffd0ee
3 changed files with 18 additions and 44 deletions
|
@ -3273,24 +3273,13 @@ terminating the main thread.
|
|||
*/
|
||||
@property TaskPool taskPool() @trusted
|
||||
{
|
||||
static bool initialized;
|
||||
__gshared static TaskPool pool;
|
||||
|
||||
if(!initialized)
|
||||
{
|
||||
synchronized(typeid(TaskPool))
|
||||
{
|
||||
if(!pool)
|
||||
{
|
||||
pool = new TaskPool(defaultPoolThreads);
|
||||
pool.isDaemon = true;
|
||||
}
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return pool;
|
||||
import std.concurrency : initOnce;
|
||||
__gshared TaskPool pool;
|
||||
return initOnce!pool({
|
||||
auto p = new TaskPool(defaultPoolThreads);
|
||||
p.isDaemon = true;
|
||||
return p;
|
||||
}());
|
||||
}
|
||||
|
||||
private shared uint _defaultPoolThreads;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue