This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Expand file tree Collapse file tree 2 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -596,7 +596,10 @@ class Thread
596
596
*/
597
597
~this () nothrow @nogc
598
598
{
599
- if ( m_addr == m_addr.init )
599
+ bool no_context = m_addr == m_addr.init;
600
+ bool not_registered = ! next && ! prev && (sm_tbeg ! is this );
601
+
602
+ if (no_context || not_registered)
600
603
{
601
604
return ;
602
605
}
@@ -1856,8 +1859,9 @@ private:
1856
1859
do
1857
1860
{
1858
1861
// Thread was already removed earlier, might happen b/c of thread_detachInstance
1859
- if (! t.next && ! t.prev)
1862
+ if (! t.next && ! t.prev && (sm_tbeg ! is t) )
1860
1863
return ;
1864
+
1861
1865
slock.lock_nothrow();
1862
1866
{
1863
1867
// NOTE: When a thread is removed from the global thread list its
Original file line number Diff line number Diff line change 1
1
import core.sys.posix.pthread ;
2
2
import core.memory ;
3
+ import core.thread ;
4
+
5
+ extern (C ) void rt_moduleTlsCtor();
6
+ extern (C ) void rt_moduleTlsDtor();
3
7
4
8
extern (C )
5
- void * entry_point (void * )
9
+ void * entry_point1 (void * )
6
10
{
7
11
// try collecting - GC must ignore this call because this thread
8
12
// is not registered in runtime
9
13
GC .collect();
10
14
return null ;
11
15
}
12
16
17
+ extern (C )
18
+ void * entry_point2 (void * )
19
+ {
20
+ // This thread gets registered in druntime, does some work and gets
21
+ // unregistered to be cleaned up manually
22
+ thread_attachThis();
23
+ rt_moduleTlsCtor();
24
+
25
+ auto x = new int [10 ];
26
+
27
+ rt_moduleTlsDtor();
28
+ thread_detachThis();
29
+ return null ;
30
+ }
31
+
13
32
void main ()
14
33
{
15
34
// allocate some garbage
16
35
auto x = new int [1000 ];
17
36
18
- pthread_t thread;
19
- auto status = pthread_create(&thread, null , &entry_point, null );
20
- assert (status == 0 );
21
- pthread_join(thread, null );
37
+ {
38
+ pthread_t thread;
39
+ auto status = pthread_create(&thread, null , &entry_point1, null );
40
+ assert (status == 0 );
41
+ pthread_join(thread, null );
42
+ }
43
+
44
+ {
45
+ pthread_t thread;
46
+ auto status = pthread_create(&thread, null , &entry_point2, null );
47
+ assert (status == 0 );
48
+ pthread_join(thread, null );
49
+ }
22
50
}
You can’t perform that action at this time.
0 commit comments