Skip to content

Instantly share code, notes, and snippets.

@dnadlinger
Created September 20, 2010 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnadlinger/587964 to your computer and use it in GitHub Desktop.
Save dnadlinger/587964 to your computer and use it in GitHub Desktop.
module test;
import core.thread;
import std.conv;
import std.range;
import std.string;
enum THREADS = iota(0, 9);
enum WORK_RANGE = iota(0, 30000);
void main() {
Thread[] threads;
// Invoke the threads.
foreach (i; THREADS) {
auto thread = new Thread(&run);
threads ~= thread;
thread.start();
}
// Wait for the threads to finish.
foreach (i, thread; threads) {
thread.join(true);
}
}
void run() {
foreach (i; WORK_RANGE) {
string data = to!string(toStringz("Some random string which contains some random words."));
}
}
$ dmd -gc Documents/code/d/tests/threads/test.d; gdb ./test
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/aule/test...done.
(gdb) handle SIGUSR1 nostop
Signal Stop Print Pass to program Description
SIGUSR1 No Yes Yes User defined signal 1
(gdb) handle SIGUSR2 nostop
Signal Stop Print Pass to program Description
SIGUSR2 No Yes Yes User defined signal 2
(gdb) r
Starting program: /home/aule/test
[Thread debugging using libthread_db enabled]
[New Thread 0xf7d46b70 (LWP 15896)]
[New Thread 0xf7545b70 (LWP 15897)]
[New Thread 0xf6d44b70 (LWP 15898)]
[New Thread 0xf6543b70 (LWP 15899)]
[New Thread 0xf5d42b70 (LWP 15900)]
[New Thread 0xf5541b70 (LWP 15901)]
[New Thread 0xf4d40b70 (LWP 15902)]
[New Thread 0xf453fb70 (LWP 15903)]
[New Thread 0xf3d3eb70 (LWP 15904)]
Program received signal SIGUSR1, User defined signal 1.
[Thread 0xf5d42b70 (LWP 15900) exited]
[Thread 0xf5541b70 (LWP 15901) exited]
^C
Program received signal SIGINT, Interrupt.
0xf7fdf430 in __kernel_vsyscall ()
(gdb) thread apply all bt
Thread 10 (Thread 0xf3d3eb70 (LWP 15904)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c31a in core.thread.thread_findByAddr() ()
#7 0x0804bf1f in core.thread.Thread.getThis() ()
#8 0x08061212 in thread_suspendHandler ()
#9 <signal handler called>
#10 0xf7f19f98 in clone () from /usr/lib32/libc.so.6
#11 0x003d0f00 in ?? ()
#12 0x00000000 in ?? ()
Thread 9 (Thread 0xf453fb70 (LWP 15903)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c182 in core.thread.Thread.add() ()
#7 0x0805028a in thread_entryPoint ()
#8 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#9 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 8 (Thread 0xf4d40b70 (LWP 15902)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c182 in core.thread.Thread.add() ()
#7 0x0805028a in thread_entryPoint ()
#8 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#9 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 5 (Thread 0xf6543b70 (LWP 15899)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc6b45 in sem_wait@@GLIBC_2.1 () from /usr/lib32/libpthread.so.0
#2 0x0805d036 in core.thread.thread_suspendAll() ()
#3 0x0805cf8d in thread_suspendAll ()
#4 0x08052cf0 in gc.gcx.Gcx.fullcollect() ()
#5 0x08052cce in gc.gcx.Gcx.fullcollectshell() ()
#6 0x08050ff9 in gc.gcx.GC.mallocNoSync() ()
#7 0x08050f3b in gc.gcx.GC.malloc() ()
#8 0x08050856 in gc_qalloc ()
#9 0x080540b4 in _d_newarrayiT ()
#10 0x0804f052 in std.string.toStringz() ()
#11 0x0804942b in test.run () at Documents/code/d/tests/threads/test.d:29
#12 0x0804c0f9 in core.thread.Thread.run() ()
#13 0x080502d3 in thread_entryPoint ()
#14 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#15 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 4 (Thread 0xf6d44b70 (LWP 15898)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c182 in core.thread.Thread.add() ()
#7 0x0805028a in thread_entryPoint ()
#8 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#9 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 3 (Thread 0xf7545b70 (LWP 15897)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c182 in core.thread.Thread.add() ()
#7 0x0805028a in thread_entryPoint ()
#8 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#9 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 2 (Thread 0xf7d46b70 (LWP 15896)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc7429 in __lll_lock_wait () from /usr/lib32/libpthread.so.0
#2 0xf7fc24f9 in _L_lock_572 () from /usr/lib32/libpthread.so.0
#3 0xf7fc238b in pthread_mutex_lock () from /usr/lib32/libpthread.so.0
#4 0x0804f609 in _d_monitor_lock ()
#5 0x0804fd57 in _d_monitorenter ()
#6 0x0804c182 in core.thread.Thread.add() ()
#7 0x0805028a in thread_entryPoint ()
#8 0xf7fbfe60 in start_thread () from /usr/lib32/libpthread.so.0
#9 0xf7f19fae in clone () from /usr/lib32/libc.so.6
Thread 1 (Thread 0xf7e47750 (LWP 15893)):
#0 0xf7fdf430 in __kernel_vsyscall ()
#1 0xf7fc0ede in pthread_join () from /usr/lib32/libpthread.so.0
#2 0x0804bbef in core.thread.Thread.join() ()
#3 0x080493db in D main () at Documents/code/d/tests/threads/test.d:22
#4 0x0804d966 in rt.dmain2.main() ()
#5 0x0804d8c0 in rt.dmain2.main() ()
#6 0x0804d9aa in rt.dmain2.main() ()
#7 0x0804d8c0 in rt.dmain2.main() ()
#8 0x0804d866 in main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment