Skip to content

Commit fa39a32

Browse files
committed
Merge pull request #589 from dawgfoto/threadTermLocks
add explicit thread_term call to replace atexit
2 parents 7ad4524 + 619373b commit fa39a32

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/core/thread.d

+15-6
Original file line numberDiff line numberDiff line change
@@ -1397,13 +1397,12 @@ private:
13971397
lock[] = Mutex.classinfo.init[];
13981398
(cast(Mutex)lock.ptr).__ctor();
13991399
}
1400+
}
14001401

1401-
extern(C) void destroy()
1402-
{
1403-
foreach (ref lock; _locks)
1404-
(cast(Mutex)lock.ptr).__dtor();
1405-
}
1406-
atexit(&destroy);
1402+
static void termLocks()
1403+
{
1404+
foreach (ref lock; _locks)
1405+
(cast(Mutex)lock.ptr).__dtor();
14071406
}
14081407

14091408
__gshared Context* sm_cbeg;
@@ -1730,6 +1729,16 @@ extern (C) void thread_init()
17301729
}
17311730

17321731

1732+
/**
1733+
* Terminates the thread module. No other thread routine may be called
1734+
* afterwards.
1735+
*/
1736+
extern (C) void thread_term()
1737+
{
1738+
Thread.termLocks();
1739+
}
1740+
1741+
17331742
/**
17341743
*
17351744
*/

src/core/thread.di

+7
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ private:
436436
extern (C) void thread_init();
437437

438438

439+
/**
440+
* Terminates the thread module. No other thread routine may be called
441+
* afterwards.
442+
*/
443+
extern (C) void thread_term();
444+
445+
439446
/**
440447
*
441448
*/

src/gc/proxy.d

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private
2929
__gshared gc_t _gc;
3030

3131
extern (C) void thread_init();
32+
extern (C) void thread_term();
3233

3334
struct Proxy
3435
{
@@ -136,8 +137,9 @@ extern (C)
136137
// the problems mentioned above though, so I guess we'll see.
137138
_gc.fullCollectNoStack(); // not really a 'collect all' -- still scans
138139
// static data area, roots, and ranges.
139-
_gc.Dtor();
140+
thread_term();
140141

142+
_gc.Dtor();
141143
free(cast(void*)_gc);
142144
_gc = null;
143145
}

0 commit comments

Comments
 (0)