Skip to content

Commit d241d00

Browse files
author
Simon Lepasteur
committed
Lazy instantiation of threadpool shared instance.
Lazy instantiation of thread pool shared instance enable forking linux processes using cpp rest library as long as the thread pool is not used before the fork.
1 parent b7909b3 commit d241d00

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

Release/include/pplx/threadpool.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,9 @@ class threadpool
7272
for (size_t i = 0; i < n; i++)
7373
add_thread();
7474
}
75-
#if defined(__ANDROID__)
75+
7676
static threadpool& shared_instance();
77-
#else
78-
static threadpool& shared_instance()
79-
{
80-
return s_shared;
81-
}
82-
#endif
77+
8378
~threadpool()
8479
{
8580
m_service.stop();
@@ -105,10 +100,6 @@ class threadpool
105100
private:
106101
struct _cancel_thread { };
107102

108-
#if !defined(__ANDROID__)
109-
static threadpool s_shared;
110-
#endif
111-
112103
void add_thread()
113104
{
114105
pthread_t t;

Release/src/pplx/threadpool.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ threadpool& threadpool::shared_instance()
6161
#else
6262

6363
// initialize the static shared threadpool
64-
threadpool threadpool::s_shared(40);
64+
threadpool& threadpool::shared_instance()
65+
{
66+
static threadpool s_shared(40);
67+
return s_shared;
68+
}
6569

6670
#endif
6771

0 commit comments

Comments
 (0)