vibe-d / vibe-core

Repository for the next generation of vibe.d's core package.
MIT License
61 stars 46 forks source link

Error creating thread error #185

Open gedaiu opened 4 years ago

gedaiu commented 4 years ago

I get an Core.thread.osthread.ThreadError@src/core/thread/osthread.d(3176): Error creating thread when I run a task intensive app. Does anyone know how I could debug this?

[Thread 0x7fbfb43b6700 (LWP 474407) exited]
core.thread.osthread.ThreadError@src/core/thread/osthread.d(3176): Error creating thread
----------------

Thread 1 "mesolite" received signal SIGABRT, Aborted.
0x00007ffff77e5625 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff77e5625 in raise () from /lib64/libc.so.6
#1  0x00007ffff77ce8d9 in abort () from /lib64/libc.so.6
#2  0x0000000000c99ce8 in vibe.core.task.TaskFiber.run() (this=0x7fff6412d000)
    at ../../../../.dub/packages/vibe-core-1.7.0/vibe-core/source/vibe/core/task.d:459
#3  0x0000000000d79c82 in core.thread.fiber.Fiber.run() ()
#4  0x0000000000d79b67 in fiber_entryPoint ()
#5  0x0000000000000000 in ?? ()
(gdb) info threads
  Id   Target Id                                     Frame 
* 1    Thread 0x7ffff778b640 (LWP 441553) "mesolite" 0x00007ffff77e5625 in raise () from /lib64/libc.so.6
  2    Thread 0x7ffff7fcc700 (LWP 441557) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  3    Thread 0x7ffff7fc7700 (LWP 441558) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  4    Thread 0x7ffff7fc2700 (LWP 441559) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  5    Thread 0x7ffff7fbd700 (LWP 441560) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  6    Thread 0x7ffff7fb8700 (LWP 441561) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  7    Thread 0x7ffff7788700 (LWP 441562) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  8    Thread 0x7ffff7783700 (LWP 441563) "mesolite" 0x00007ffff7af5d45 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
(gdb) 
gedaiu commented 4 years ago

vibe core creates the threads even if I do this in my main function:

  int main() {
    setupWorkerThreads(0);
s-ludwig commented 2 months ago

On Posix, there will be a thread pool for file I/O operations and using most functions in vibe.core.file will also spawn separate I/O worker threads (nowadays). Getting by without any threads is unfortunately difficult (requiring low-level hacks) or outright impossible for certain asynchronous operations.

However, as long as threads in general work, the amount of threads created/used should be constant, unless I'm forgetting something. So the call stack that seems to imply that TaskFiber.run() might be responsible for creating a new thread is definitely not complete.

If this was still a current issue, I would probably try to set a breakpoint at pthread_create to see where the threads are actually created from.

For the record, eventcore creates 4 threads for its I/O and the separate pool in vibe-core has 3 additional threads. So with setupWorkerThreads(1) that should result in 8 worker threads in total. Note that setupWorkerThreads(0) will actually result in logicalProcessorCount to be used as the number of worker threads.