On Wed, Sep 8, 2010 at 5:02 PM, Ivan S. Lyapunov <[email protected]> wrote:

> Hello.
>
>  I'm writed a simple pthreads program and can't understand Valgrind
>  output because thre is no error in my case I think ;)
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <pthread.h>
>
> extern "C" {
>
>        void * run_handle(void * param) {
>        printf("tra-la-la\n");
>        return 0;
>    }
> }
>
> int main(int argc, char** argv) {
>    pthread_t t;
>    pthread_create(&t, 0, run_handle, 0);
>
>    sleep(10);
>    return 0;
> }
>
>
> compile it
> gcc ./main.cpp -o main -pthread -D_REENTRANT -D_THREAD_SAFE -lpthread
>

As the first step, try adding "-g" to the compile command.

--kcc


>
> and valgrind
> valgrind --tool=helgrind -v ./main
>
> ArchLinux, i686, valgrind-3.5.0
>
> why there is errors?
>
> ==12868== Helgrind, a thread error detector
> ==12868== Copyright (C) 2007-2009, and GNU GPL'd, by OpenWorks LLP et
> al. ==12868== Using Valgrind-3.5.0 and LibVEX; rerun with -h for
> copyright info ==12868== Command: ./main
> ==12868==
> --12868-- Valgrind options:
> --12868--    --tool=helgrind
> --12868--    -v
> --12868-- Contents of /proc/version:
> --12868--   Linux version 2.6.35-ARCH (tob...@t-powa-lx) (gcc version
> 4.5.1 (GCC) ) #1 SMP PREEMPT Fri Aug 27 16:22:18 UTC 2010 --12868--
> Arch and hwcaps: X86, x86-sse1-sse2 --12868-- Page sizes: currently
> 4096, max supported 4096 --12868-- Valgrind library
> directory: /usr/lib/valgrind --12868-- Reading syms
> from /lib/ld-2.12.1.so (0x4000000) --12868-- Reading syms
> from /home/dront/Develop/git/crossplatform/FoundationTest/main
> (0x8048000) --12868-- Reading syms
> from /usr/lib/valgrind/helgrind-x86-linux (0x38000000) --12868--
> object doesn't have a symbol table --12868--    object doesn't have a
> dynamic symbol table --12868-- Reading suppressions
> file: /usr/lib/valgrind/default.supp --12868-- Reading syms
> from /usr/lib/valgrind/vgpreload_core-x86-linux.so (0x401f000)
> --12868-- Reading syms
> from /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so (0x4021000)
> --12868-- REDIR: 0x4016c20 (index) redirected to 0x4027650 (index)
> --12868-- REDIR: 0x4016dc0 (strlen) redirected to 0x4027730 (strlen)
> --12868-- Reading syms from /lib/libpthread-2.12.1.so (0x404e000)
> --12868-- Reading syms from /lib/libc-2.12.1.so (0x4068000)
> --12868--    object doesn't have a symbol table --12868-- REDIR:
> 0x40dc300 (index) redirected to 0x40275d0 (index) --12868-- REDIR:
> 0x40540b0 (pthread_create@@GLIBC_2.1) redirected to 0x40252f0
> (pthread_cre...@*) --12868-- REDIR: 0x40d9c20 (calloc) redirected to
> 0x40232f0 (calloc) --12868-- REDIR: 0x40dc9d0 (strlen) redirected to
> 0x4027710 (strlen) tra-la-la ==12868== Thread #1 is the program's root
> thread ==12868== ==12868== Thread #2 was created ==12868==    at
> 0x41371F8: clone (in /lib/libc-2.12.1.so) ==12868==    by 0x4054425:
> pthread_create@@GLIBC_2.1 (in /lib/libpthread-2.12.1.so) ==12868==
> by 0x40251E1: pthread_create_WRK
> (in /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so) ==12868==    by
> 0x80484D9: main
> (in /home/dront/Develop/git/crossplatform/FoundationTest/main)
> ==12868== ==12868== Possible data race during read of size 4 at
> 0xbe87819c by thread #1 ==12868==    at 0x40251EF: pthread_create_WRK
> (in /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so) ==12868==    by
> 0x80484D9: main
> (in /home/dront/Develop/git/crossplatform/FoundationTest/main)
> ==12868==  This conflicts with a previous write of size 4 by thread #2
> ==12868==    at 0x40252C9: mythread_wrapper
> (in /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so) ==12868==    by
> 0x4053E5F: start_thread (in /lib/libpthread-2.12.1.so) ==12868==    by
> 0x413720D: clone (in /lib/libc-2.12.1.so) ==12868== --12868-- REDIR:
> 0x40d9160 (free) redirected to 0x4023da0 (free) --12868-- REDIR:
> 0x40561f0 (pthread_mutex_lock) redirected to 0x4025680
> (pthread_mutex_lock) --12868-- REDIR: 0x40577c0 (pthread_mutex_unlock)
> redirected to 0x4025a60 (pthread_mutex_unlock) ==12868== ==12868==
> ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 23 from 23)
> ==12868== ==12868== 1 errors in context 1 of 1: ==12868== Possible data
> race during read of size 4 at 0xbe87819c by thread #1 ==12868==    at
> 0x40251EF: pthread_create_WRK
> (in /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so) ==12868==    by
> 0x80484D9: main
> (in /home/dront/Develop/git/crossplatform/FoundationTest/main)
> ==12868==  This conflicts with a previous write of size 4 by thread #2
> ==12868==    at 0x40252C9: mythread_wrapper
> (in /usr/lib/valgrind/vgpreload_helgrind-x86-linux.so) ==12868==    by
> 0x4053E5F: start_thread (in /lib/libpthread-2.12.1.so) ==12868==    by
> 0x413720D: clone (in /lib/libc-2.12.1.so) ==12868== --12868-- --12868--
> used_suppression:     23 helgrind-glibc2X-004 ==12868== ==12868== ERROR
> SUMMARY: 1 errors from 1 contexts (suppressed: 23 from 23)
>
>
>
> cat /proc/cpuinfo
> processor       : 0
> vendor_id       : GenuineIntel
> cpu family      : 15
> model           : 2
> model name      : Intel(R) Pentium(R) 4 CPU 3.06GHz
> stepping        : 7
> cpu MHz         : 3066.602
> cache size      : 512 KB
> physical id     : 0
> siblings        : 2
> core id         : 0
> cpu cores       : 1
> apicid          : 0
> initial apicid  : 0
> fdiv_bug        : no
> hlt_bug         : no
> f00f_bug        : no
> coma_bug        : no
> fpu             : yes
> fpu_exception   : yes
> cpuid level     : 2
> wp              : yes
> flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
> pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe
> pebs bts cid bogomips   : 6135.75 clflush size  : 64
> cache_alignment : 128
> address sizes   : 36 bits physical, 32 bits virtual
> power management:
>
> processor       : 1
> vendor_id       : GenuineIntel
> cpu family      : 15
> model           : 2
> model name      : Intel(R) Pentium(R) 4 CPU 3.06GHz
> stepping        : 7
> cpu MHz         : 3066.602
> cache size      : 512 KB
> physical id     : 0
> siblings        : 2
> core id         : 0
> cpu cores       : 1
> apicid          : 1
> initial apicid  : 1
> fdiv_bug        : no
> hlt_bug         : no
> f00f_bug        : no
> coma_bug        : no
> fpu             : yes
> fpu_exception   : yes
> cpuid level     : 2
> wp              : yes
> flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr
> pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe
> pebs bts cid bogomips   : 6135.53 clflush size  : 64
> cache_alignment : 128
> address sizes   : 36 bits physical, 32 bits virtual
> power management:
>
>
> Regards,
>  Ivan
>
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Valgrind-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/valgrind-users
>
>
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to