GC collecting "too much"..

simendsjo simendsjo at gmail.com
Thu Mar 29 05:14:10 PDT 2012


On Mon, 26 Mar 2012 20:15:40 +0200, simendsjo <simendsjo at gmail.com> wrote:

> On Mon, 26 Mar 2012 17:10:34 +0200, Timon Gehr <timon.gehr at gmx.ch> wrote:
>
>> On 03/26/2012 11:55 AM, simendsjo wrote:
>>> It seems threads created in the c library is totally unknown to D. How
>>> can I make D aware of these threads when there is no library support  
>>> for
>>> it?
>>
>> You may be looking for this:
>> http://dlang.org/phobos/core_thread.html#thread_attachThis
>
> Thanks, but I tried that too and couldn't get it to work.
>
> I added the following:
>
> extern(C) handler()
> {
>      synchronized // needed here to avoid the GC to collect while  
> attaching thread?
>      {
>          if(!Thread.getThis()) // thread unknown to D
>          {
>              thread_attachThis();
>              assert(Thread.getThis()); // now D knows about it
>          }
>      }
>      GC.collect(); // still segfaults
> }
>
> Actually, using attachThis segfaults GC.collect() outside the thread  
> handling code too.


Some info from gdb:

[New Thread 0xf7cfcb70 (LWP 18614)]
[New Thread 0xf74fbb70 (LWP 18615)]

Program received signal SIGUSR1, User defined signal 1.
0xf7fdd430 in __kernel_vsyscall ()

(gdb) info threads
   Id   Target Id         Frame
   3    Thread 0xf74fbb70 (LWP 18615) "main" 0xf7fdd430 in  
__kernel_vsyscall ()
   2    Thread 0xf7cfcb70 (LWP 18614) "main" 0xf7fdd430 in  
__kernel_vsyscall ()
* 1    Thread 0xf7dfd9c0 (LWP 18611) "main" 0xf7fdd430 in  
__kernel_vsyscall ()

(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xf74fbb70 (LWP 18615)]
0x080855b4 in gc.gcx.Gcx.mark() ()
(gdb) info threads
   Id   Target Id         Frame
* 3    Thread 0xf74fbb70 (LWP 18615) "main" 0x080855b4 in  
gc.gcx.Gcx.mark() ()
   2    Thread 0xf7cfcb70 (LWP 18614) "main" 0xf7fdd430 in  
__kernel_vsyscall ()
   1    Thread 0xf7dfd9c0 (LWP 18611) "main" 0xf7fdd430 in  
__kernel_vsyscall ()

------------

And if I change the code to:
extern(C) handler()
{
     GC.collect();
}

[New Thread 0xf7cfcb70 (LWP 21454)]
[New Thread 0xf74fbb70 (LWP 21455)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xf74fbb70 (LWP 21455)]
0x0808970e in core.thread.thread_suspendAll() ()
(gdb) info threads
   Id   Target Id         Frame
* 3    Thread 0xf74fbb70 (LWP 21455) "main" 0x0808970e in  
core.thread.thread_suspendAll() ()
   2    Thread 0xf7cfcb70 (LWP 21454) "main" 0xf7fdd430 in  
__kernel_vsyscall ()
   1    Thread 0xf7dfd9c0 (LWP 21451) "main" 0xf7fdd430 in  
__kernel_vsyscall ()


-----

Any idea where I should go from here?


More information about the Digitalmars-d-learn mailing list