www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D create many thread

reply Eko Wahyudin <eko.wahyudin yahoo.co.id> writes:
Hi all,

I'm create a small (hallo world) application, with DMD.
But my program create 7 annoying threads when create an empty 
class.

What is this thread for?
and is it normal in D?

Below the stack trace of thread creation.


/usr/lib/libpthread.so.0

core.thread.osthread.createLowLevelThread(void() nothrow 
delegate, uint, void() nothrow delegate) ()

_D2gc4impl12conservativeQw3Gcx16startScanThreadsMFNbZv ()

_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()

_D2gc4impl12conservativeQw3Gcx10smallAllocMFNbmKmkxC8TypeInfoZPv 
()

_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQF
MFNbKmKkKmKxQDsZQDl ()

_D2gc4impl12conservativeQw14ConservativeGC6mallocMFNbmkxC8TypeInfoZPv ()


_D2gc4impl5protoQo7ProtoGC6mallocMFNbmkxC8TypeInfoZPv ()



(gdb) info threads
   Id   Target Id                                Frame
* 1    Thread 0x7ffff7c1ea40 (LWP 8288) "jala2" 
0x00007ffff7f637a0 in pthread_create  GLIBC_2.2.5 () from 
/usr/lib/libpthread.so.0
   2    Thread 0x7ffff7fcc700 (LWP 8289) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
   3    Thread 0x7ffff7fc7700 (LWP 8317) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
   4    Thread 0x7ffff7fc2700 (LWP 8329) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
   5    Thread 0x7ffff7fbd700 (LWP 8439) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
   6    Thread 0x7ffff7fb8700 (LWP 8445) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
   7    Thread 0x7ffff7fb3700 (LWP 8463) "jala2" 
0x00007ffff7f69c45 in pthread_cond_wait  GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0


Thank you in advance.
Feb 05 2020
next sibling parent MoonlightSentinel <moonlightsentinel disroot.org> writes:
On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote:
 What is this thread for?
 and is it normal in D?
According to the stack trace your applications triggered a GC cycle. The marking is done in parallel to minimize pause times, see https://dlang.org/spec/garbage.html
Feb 05 2020
prev sibling next sibling parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 2/5/20 8:05 AM, Eko Wahyudin wrote:
 Hi all,
 
 I'm create a small (hallo world) application, with DMD.
 But my program create 7 annoying threads when create an empty class.
 
 What is this thread for?
 and is it normal in D?
 Thank you in advance.
I didn't know about this feature. I was going to respond that it is not normal, but this was added almost a year ago. First, I think this is a bit over the top. A hello world program should not spawn threads to aid in marking. Looking at the PR that made this happen, I think the author originally had reservations about it: https://github.com/dlang/druntime/pull/2514#issuecomment-487090334 I think we should be more selective about when we make parallel threads to scan (maybe above a certain size of used memory?). -Steve
Feb 05 2020
next sibling parent Gregor =?UTF-8?B?TcO8Y2ts?= <gregormueckl gmx.de> writes:
On Wednesday, 5 February 2020 at 15:54:23 UTC, Steven 
Schveighoffer wrote:
 I think we should be more selective about when we make parallel 
 threads to scan (maybe above a certain size of used memory?).

 -Steve
That threshold would have to adapt to each system. How about delaying thread startup until the first actual mark phase or the first run after the first 100ms of runtime or so? The main goal should be to minimize the runtime impact. It doesn't even make sense to me to run a GC cycle for a program that runs for a extremely short time only.
Feb 05 2020
prev sibling parent reply uranuz <neuranuz gmail.com> writes:
Is it also possible to set some custom thread name for GC threads 
in order to be distinguishable from other threads in utilities 
like `htop`? It would be handy...
Feb 06 2020
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 07/02/2020 8:53 AM, uranuz wrote:
 Is it also possible to set some custom thread name for GC threads in 
 order to be distinguishable from other threads in utilities like `htop`? 
 It would be handy...
https://dlang.org/phobos/core_thread_osthread.html#.Thread.name.2
Feb 06 2020
prev sibling parent reply tchaloupka <chalucha gmail.com> writes:
On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote:
 Hi all,

 I'm create a small (hallo world) application, with DMD.
 But my program create 7 annoying threads when create an empty 
 class.
If you don't want the parallel sweep enabled for your app, you can turn it of ie with: ``` extern(C) __gshared string[] rt_options = [ "gcopt=parallel:0" ]; ``` Or in various other ways as described in mentioned documentation: https://dlang.org/spec/garbage.html#gc_config
Feb 06 2020
parent reply bauss <jj_1337 live.dk> writes:
On Thursday, 6 February 2020 at 22:00:26 UTC, tchaloupka wrote:
 On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin 
 wrote:
 Hi all,

 I'm create a small (hallo world) application, with DMD.
 But my program create 7 annoying threads when create an empty 
 class.
If you don't want the parallel sweep enabled for your app, you can turn it of ie with: ``` extern(C) __gshared string[] rt_options = [ "gcopt=parallel:0" ]; ``` Or in various other ways as described in mentioned documentation: https://dlang.org/spec/garbage.html#gc_config
Why are we doing it like that? That's the least user-friendly method of configuring the GC I have ever seen.
Feb 06 2020
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 2/7/20 2:34 AM, bauss wrote:
 On Thursday, 6 February 2020 at 22:00:26 UTC, tchaloupka wrote:
 On Wednesday, 5 February 2020 at 13:05:59 UTC, Eko Wahyudin wrote:
 Hi all,

 I'm create a small (hallo world) application, with DMD.
 But my program create 7 annoying threads when create an empty class.
If you don't want the parallel sweep enabled for your app, you can turn it of ie with: ``` extern(C) __gshared string[] rt_options = [ "gcopt=parallel:0" ]; ``` Or in various other ways as described in mentioned documentation: https://dlang.org/spec/garbage.html#gc_config
Why are we doing it like that? That's the least user-friendly method of configuring the GC I have ever seen.
The reason this has to be configured this way is because the parallel scanning is an implementation detail, and shouldn't be exposed via the core.memory.GC interface. But I still maintain, a hello world program should not need this to avoid spawning 6 threads to scan itself. -Steve
Feb 07 2020
parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 07/02/2020 16:52, Steven Schveighoffer wrote:
 But I still maintain, a hello world program should not need this to
 avoid spawning 6 threads to scan itself.
I agree, see https://issues.dlang.org/show_bug.cgi?id=20567 and https://github.com/dlang/druntime/pull/2933
Feb 08 2020