Qt Labs Forum » Qt Concurrent

puzzling erros/crashes

(1 post)
  • Started 1 year ago by michaelberg

  1. michaelberg
    michaelberg
    Member

    Hi,

    I'm trying to use QtConcurrent for some of my work, but get all kinds of weird crashes, segfaults and the like. I post this because I hope some of you Trolltech guys or maby somebody else has an idea. When I run my more complex code, the code sometimes runs, sometimes crashes with some GThread error (GThread-ERROR **: GThread system may only be initialized once.) or telling the g_thread_init is supposed to be called only once or just the more unspecific "memory access error". I also suspected some leaking memory because of some of the errors and started to try to find it via some tools, e.g. valgrind. But even though all the tools kind of report potential memory losses, it doesn't make always sense - for instance using mtrace it points me to a place in my original code where there should be nothing.
    The common thing among all seams to be that usually QtConcurrent is involved, maybe just indirctly via GThread or some gnome libs. I'm developing in C++ under Linux (64-bit Suse 10.1) for only 9 month now, so maybe I'm missing something obvious or essential, maybe not.
    Below is some testcode which doesn't show the error during running (at maximum it get very seldomly a "memory access error". But if run with

    valgrind --tool=memcheck --leak-check=yes -v erosion

    it crashes always. The output of valgrind is below the code. Maybe this is on OS issue and just manifests if using QtConcurrent or a mistake of mine, but I hope somebody has a hint or where to look further. For what I need right now using QtConcurrent with Futures is the simplest I can get, so I would like to use.

    Thanks for any help.

    Michael

    main.cpp

    
    #include <QString>
    #include <QDebug>
    
    #include "qtconcurrent.h"
    
    using namespace QtConcurrent;
    
    struct dummy {
    	dummy(int a, int b, QString c) : a(a), b(b), c(c) {}
    	int a;
    	int b;
    	QString c;
    };
    
    dummy* doX(){
    	int a = 0;
    	for(int i = 0; i < 100000000; i++)
    		a++;
    	qDebug() << a;
    	return new dummy(1, 2, "blabla");
    }
    
    dummy* doY(){
    	int a = 0;
    	for(int i = 0; i < 100000000; i++)
    		a++;
    	qDebug() << a;
    	return new dummy(3, 4, "bloblo");
    }
    
    Q_DECLARE_METATYPE(dummy*);
    
    int main(int argc, char **argv){
    	QFuture<dummy*> df1 = run(doX);
    	QFuture<dummy*> df2 = run(doY);
    
    	qDebug() << "a+b=" << (df1.result()->a + df1.result()->b)
    	<< "c: " << df1.result()->c;
    	qDebug() << "a+b=" << (df2.result()->a + df2.result()->b)
    	<< "c: " << df2.result()->c; 
    
    	delete df1.result();
    	delete df2.result();
    }
    

    unspecific memory access error (sometimes) if running the example above alone with current QtConcurrent

    
    100000000
    a+b= 3 c:  "blabla"
    100000000
    a+b= 7 c:  "bloblo"
    Speicherzugriffsfehler
    

    
    ==6594== Memcheck, a memory error detector.
    ==6594== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
    ==6594== Using LibVEX rev 1575, a library for dynamic binary translation.
    ==6594== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
    ==6594== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
    ==6594== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
    ==6594==
    --6594-- Command line
    --6594--    erosion
    --6594-- Startup, with flags:
    --6594--    --tool=memcheck
    --6594--    --leak-check=yes
    --6594--    -v
    --6594-- Contents of /proc/version:
    --6594--   Linux version 2.6.16.13-4-smp (geeko@buildhost) (gcc version 4.1.0 (SUSE Linux)) #1 SMP Wed May 3 04:53:23 UTC 2006
    --6594-- Arch and subarch: AMD64, NONE
    --6594-- Valgrind library directory: /usr/lib64/valgrind
    --6594-- Reading syms from /home/berg/development/landcare/models/erosion/erosion/erosion (0x400000)
    --6594-- Reading syms from /lib64/ld-2.4.so (0x4000000)
    --6594-- Reading syms from /usr/lib64/valgrind/amd64-linux/memcheck (0x70000000)
    --6594--    object doesn't have a symbol table
    --6594--    object doesn't have a dynamic symbol table
    --6594-- Reading suppressions file: /usr/lib64/valgrind/default.supp
    --6594-- Reading syms from /usr/lib64/valgrind/amd64-linux/vgpreload_core.so (0x491D000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so (0x4A1E000)
    --6594--    object doesn't have a symbol table
    --6594-- REDIR: 0x40131E0 (index) redirected to 0x4A213A0 (index)
    --6594-- REDIR: 0x4013390 (strcmp) redirected to 0x4A21510 (strcmp)
    --6594-- REDIR: 0x40136D0 (strlen) redirected to 0x4A21440 (strlen)
    --6594-- Reading syms from /usr/local/Trolltech/Qt-4.3.1/lib/libQtGui.so.4.3.1 (0x4B24000)
    --6594-- Reading debug info from /usr/local/Trolltech/Qt-4.3.1/lib/libQtGui.so.4.3.1.debug...
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/lib64/libpng.so.3.1.2.8 (0x5440000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libSM.so.6.0 (0x557C000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libICE.so.6.4 (0x5686000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXi.so.6.0 (0x57A1000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXrender.so.1.2.2 (0x58A9000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXrandr.so.2.0 (0x59B2000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXfixes.so.3.0 (0x5AB5000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXcursor.so.1.0.2 (0x5BBA000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXinerama.so.1.0 (0x5CC4000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/lib64/libfreetype.so.6.3.8 (0x5DC6000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/lib64/libfontconfig.so.1.0.4 (0x5F41000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libXext.so.6.4 (0x6084000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/X11R6/lib64/libX11.so.6.2 (0x6195000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /usr/local/Trolltech/Qt-4.3.1/lib/libQtCore.so.4.3.1 (0x63A3000)
    --6594-- Reading debug info from /usr/local/Trolltech/Qt-4.3.1/lib/libQtCore.so.4.3.1.debug...
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /lib64/libz.so.1.2.3 (0x664D000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /opt/gnome/lib64/libgthread-2.0.so.0.800.5 (0x6761000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /opt/gnome/lib64/libglib-2.0.so.0.800.5 (0x6865000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /lib64/librt-2.4.so (0x69F8000)
    --6594-- Reading syms from /lib64/libdl-2.4.so (0x6B01000)
    --6594-- Reading syms from /lib64/libpthread-2.4.so (0x6C05000)
    --6594-- Reading syms from /usr/lib64/libstdc++.so.6.0.8 (0x6D1B000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /lib64/libm-2.4.so (0x6F1C000)
    --6594-- Reading syms from /lib64/libgcc_s.so.1 (0x7071000)
    --6594--    object doesn't have a symbol table
    --6594-- Reading syms from /lib64/libc-2.4.so (0x717E000)
    --6594-- Reading syms from /usr/lib64/libexpat.so.1.5.0 (0x73AE000)
    --6594--    object doesn't have a symbol table
    --6594-- REDIR: 0x71F1AF0 (memset) redirected to 0x4A21620 (memset)
    --6594-- REDIR: 0x71F30A0 (memcpy) redirected to 0x4A21F20 (memcpy)
    --6594-- REDIR: 0x71F0D30 (rindex) redirected to 0x4A21250 (rindex)
    --6594-- REDIR: 0x71F0690 (strlen) redirected to 0x4A21400 (strlen)
    --6594-- REDIR: 0x6DD91D0 (operator new(unsigned long)) redirected to 0x4A20D37 (operator new(unsigned long))
    --6594-- REDIR: 0x71ECD10 (malloc) redirected to 0x4A205A0 (malloc)
    --6594-- REDIR: 0x71ED1A0 (realloc) redirected to 0x4A20643 (realloc)
    --6594-- REDIR: 0x71F1980 (memmove) redirected to 0x4A21650 (memmove)
    --6594-- REDIR: 0x71F1410 (memchr) redirected to 0x4A21550 (memchr)
    --6594-- REDIR: 0x71EA950 (free) redirected to 0x4A2020A (free)
    --6594-- REDIR: 0x6DD9300 (operator new[](unsigned long)) redirected to 0x4A20A0F (operator new[](unsigned long))
    --6594-- REDIR: 0x71EC780 (calloc) redirected to 0x4A1FA1B (calloc)
    --6594-- REDIR: 0x71F0BC0 (strncmp) redirected to 0x4A21460 (strncmp)
    --6594-- REDIR: 0x71F0C80 (strncpy) redirected to 0x4A219B0 (strncpy)
    --6594-- REDIR: 0x71EF900 (strcmp) redirected to 0x4A214D0 (strcmp)
    --6594-- REDIR: 0x6DD7FD0 (operator delete(void*)) redirected to 0x4A1FF71 (operator delete(void*))
    --6594-- REDIR: 0x71EF750 (index) redirected to 0x4A21340 (index)
    --6594-- REDIR: 0x71F28C0 (stpcpy) redirected to 0x4A21D50 (stpcpy)
    ==6594== Thread 2:
    ==6594== Invalid read of size 4
    ==6594==    at 0x6762EB5: (within /opt/gnome/lib64/libgthread-2.0.so.0.800.5)
    ==6594==    by 0x6899235: g_logv (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899382: g_log (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899405: g_assert_warning (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x689945B: (within /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x64BEBBB: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (qeventdispatcher_glib.cpp:228)
    ==6594==    by 0x64BED4F: QEventDispatcherGlib::QEventDispatcherGlib(QObject*) (qeventdispatcher_glib.cpp:279)
    ==6594==    by 0x63F219B: ??? (qthread_unix.cpp:152)
    ==6594==    by 0x63F2304: ??? (qthread_unix.cpp:176)
    ==6594==    by 0x6C0B192: start_thread (in /lib64/libpthread-2.4.so)
    ==6594==    by 0x723D47C: clone (in /lib64/libc-2.4.so)
    ==6594==  Address 0x1 is not stack'd, malloc'd or (recently) free'd
    ==6594==
    ==6594== Process terminating with default action of signal 11 (SIGSEGV)
    ==6594==  Access not within mapped region at address 0x1
    ==6594==    at 0x6762EB5: (within /opt/gnome/lib64/libgthread-2.0.so.0.800.5)
    ==6594==    by 0x6899235: g_logv (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899382: g_log (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899405: g_assert_warning (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x689945B: (within /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x64BEBBB: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (qeventdispatcher_glib.cpp:228)
    ==6594==    by 0x64BED4F: QEventDispatcherGlib::QEventDispatcherGlib(QObject*) (qeventdispatcher_glib.cpp:279)
    ==6594==    by 0x63F219B: ??? (qthread_unix.cpp:152)
    ==6594==    by 0x63F2304: ??? (qthread_unix.cpp:176)
    ==6594==    by 0x6C0B192: start_thread (in /lib64/libpthread-2.4.so)
    ==6594==    by 0x723D47C: clone (in /lib64/libc-2.4.so)
    ==6594==
    ==6594== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 3 from 1)
    ==6594==
    ==6594== 1 errors in context 1 of 1:
    ==6594== Invalid read of size 4
    ==6594==    at 0x6762EB5: (within /opt/gnome/lib64/libgthread-2.0.so.0.800.5)
    ==6594==    by 0x6899235: g_logv (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899382: g_log (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x6899405: g_assert_warning (in /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x689945B: (within /opt/gnome/lib64/libglib-2.0.so.0.800.5)
    ==6594==    by 0x64BEBBB: QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(_GMainContext*) (qeventdispatcher_glib.cpp:228)
    ==6594==    by 0x64BED4F: QEventDispatcherGlib::QEventDispatcherGlib(QObject*) (qeventdispatcher_glib.cpp:279)
    ==6594==    by 0x63F219B: ??? (qthread_unix.cpp:152)
    ==6594==    by 0x63F2304: ??? (qthread_unix.cpp:176)
    ==6594==    by 0x6C0B192: start_thread (in /lib64/libpthread-2.4.so)
    ==6594==    by 0x723D47C: clone (in /lib64/libc-2.4.so)
    ==6594==  Address 0x1 is not stack'd, malloc'd or (recently) free'd
    --6594--
    --6594-- supp:    3 Fedora-Core-5-hack2a
    ==6594==
    ==6594== IN SUMMARY: 1 errors from 1 contexts (suppressed: 3 from 1)
    ==6594==
    ==6594== malloc/free: in use at exit: 48,681 bytes in 219 blocks.
    ==6594== malloc/free: 239 allocs, 20 frees, 50,810 bytes allocated.
    ==6594==
    ==6594== searching for pointers to 219 not-freed blocks.
    ==6594== checked 17,542,816 bytes.
    ==6594==
    ==6594== Thread 1:
    ==6594==
    ==6594== 576 bytes in 2 blocks are possibly lost in loss record 39 of 43
    ==6594==    at 0x4A1FA98: calloc (in /usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
    ==6594==    by 0x400F2E9: allocate_dtv (in /lib64/ld-2.4.so)
    ==6594==    by 0x400F3AD: _dl_allocate_tls (in /lib64/ld-2.4.so)
    ==6594==    by 0x6C0B973: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.4.so)
    ==6594==    by 0x63F1DE5: QThread::start(QThread::Priority) (qthread_unix.cpp:458)
    ==6594==    by 0x4030A4: QtConcurrent::ThreadPoolPrivate::run(QtConcurrent::ThreadPoolTask*, QThread::Priority) (threadpool.cpp:146)
    ==6594==    by 0x4030E1: QtConcurrent::ThreadPool::run(QtConcurrent::ThreadPoolTask*, QThread::Priority) (threadpool.cpp:281)
    ==6594==    by 0x4044D9: QtConcurrent::TaskManager::createThreadRunner() (taskmanager.cpp:343)
    ==6594==    by 0x4046B9: QtConcurrent::TaskManager::createInitialThreadRunner() (taskmanager.cpp:334)
    ==6594==    by 0x40B625: _ZN12QtConcurrent11TaskManager3runINS_11FunctorTaskIN5boost3_bi6bind_tIP5dummyPFS7_vENS4_5list0EEEEEEENS_7QFutureINT_10ReturnTypeEEEPSE_i (taskmanager.h:141)
    ==6594==    by 0x40B6A3: _ZN12QtConcurrent11TaskManager3runIN5boost3_bi6bind_tIP5dummyPFS6_vENS3_5list0EEEEENS_7QFutureINT_11result_typeEEESC_i (taskmanager.h:163)
    ==6594==    by 0x40B71A: QtConcurrent::QFuture<dummy*> QtConcurrent::run<dummy*>(dummy* (*)(), int) (run.h:51)
    ==6594==
    ==6594== LEAK SUMMARY:
    ==6594==    definitely lost: 0 bytes in 0 blocks.
    ==6594==      possibly lost: 576 bytes in 2 blocks.
    ==6594==    still reachable: 48,105 bytes in 217 blocks.
    ==6594==         suppressed: 0 bytes in 0 blocks.
    ==6594== Reachable blocks (those to which a pointer was found) are not shown.
    ==6594== To see them, rerun with: --show-reachable=yes
    --6594--  memcheck: sanity checks: 56 cheap, 3 expensive
    --6594--  memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
    --6594--  memcheck: auxmaps: 0 searches, 0 comparisons
    --6594--  memcheck: secondaries: 54 issued (3456k, 3M)
    --6594--  memcheck: secondaries: 916 accessible and distinguished (58624k, 57M)
    --6594--     tt/tc: 9,680 tt lookups requiring 9,976 probes
    --6594--     tt/tc: 9,680 fast-cache updates, 5 flushes
    --6594-- translate: new        4,520 (104,472 -> 1,887,024; ratio 180:10) [0 scs]
    --6594-- translate: dumped     0 (0 -> ??)
    --6594-- translate: discarded  14 (360 -> ??)
    --6594-- scheduler: 2,643,672 jumps (bb entries).
    --6594-- scheduler: 54/5,958 major/minor sched events.
    --6594--    sanity: 57 cheap, 3 expensive checks.
    --6594--    exectx: 30,011 lists, 158 contexts (avg 0 per list)
    --6594--    exectx: 263 searches, 279 full compares (1,060 per 1000)
    --6594--    exectx: 2,292 cmp2, 3 cmp4, 0 cmpAll
    

    Posted: 1 year #

RSS feed for this topic

Reply

You must log in to post.



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.