שאלות על pthreads ו valgrind
היי יש לי כמה שאלות על העניין הנל.
בתוכנית שלי כל מה שאני עושה זה מתאחל את הthread בלי attr בלי כלום, ויש עושה לו pthread_cancel ויותר מהthread הראשי.
כשאני מריץ את זה בvalgrind זה מה הוא אומר (בין היתר...
)
if (pthread_create(&(threads[TOKENIZER]), NULL, tokenizer, (void*) buffer) != 0)
{
printf( " >> Error: failed to create \"tokenizer\" thread\nExiting now.");
exit(1);
}
if (pthread_create(&(threads[TAGGER]), NULL, tagger, NULL ) != 0)
{
printf(" >> Error: failed to create \"tagger\" thread\nExiting now.");
exit(1);
}
if (pthread_create(&(threads[MINER]), NULL, miner, NULL ) != 0)
{
printf(" >> Error: failed to create \"miner\" thread\nExiting now.");
exit(1);
}
לא עושה שימוש בthreads ישר יוצא ככה:
for (i = 0; i < __NUM_OF_THREADS; i++)
{
pthread_cancel(threads);
}
return 0;
הvalgrind בוכה ש:
==24050== Conditional jump or move depends on uninitialised value(s)
==24050== at 0x4E3F067: pthread_cancel (pthread_cancel.c:35)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F06D: pthread_cancel (pthread_cancel.c:35)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F080: pthread_cancel (pthread_cancel.c:48)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F0A0: pthread_cancel (pthread_cancel.c:102)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050==
==24050== HEAP SUMMARY:
==24050== in use at exit: 816 bytes in 3 blocks
==24050== total heap usage: 14 allocs, 11 frees, 3,542 bytes allocated
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 1 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400EA4: main (main.c:137)
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 2 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400EE0: main (main.c:144)
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 3 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400F1C: main (main.c:149)
==24050==
==24050== LEAK SUMMARY:
==24050== definitely lost: 0 bytes in 0 blocks
==24050== indirectly lost: 0 bytes in 0 blocks
==24050== possibly lost: 816 bytes in 3 blocks
==24050== still reachable: 0 bytes in 0 blocks
==24050== suppressed: 0 bytes in 0 blocks
==24050==
יש רעיונות?
היי יש לי כמה שאלות על העניין הנל.
בתוכנית שלי כל מה שאני עושה זה מתאחל את הthread בלי attr בלי כלום, ויש עושה לו pthread_cancel ויותר מהthread הראשי.
כשאני מריץ את זה בvalgrind זה מה הוא אומר (בין היתר...
if (pthread_create(&(threads[TOKENIZER]), NULL, tokenizer, (void*) buffer) != 0)
{
printf( " >> Error: failed to create \"tokenizer\" thread\nExiting now.");
exit(1);
}
if (pthread_create(&(threads[TAGGER]), NULL, tagger, NULL ) != 0)
{
printf(" >> Error: failed to create \"tagger\" thread\nExiting now.");
exit(1);
}
if (pthread_create(&(threads[MINER]), NULL, miner, NULL ) != 0)
{
printf(" >> Error: failed to create \"miner\" thread\nExiting now.");
exit(1);
}
לא עושה שימוש בthreads ישר יוצא ככה:
for (i = 0; i < __NUM_OF_THREADS; i++)
{
pthread_cancel(threads);
}
return 0;
הvalgrind בוכה ש:
==24050== Conditional jump or move depends on uninitialised value(s)
==24050== at 0x4E3F067: pthread_cancel (pthread_cancel.c:35)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F06D: pthread_cancel (pthread_cancel.c:35)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F080: pthread_cancel (pthread_cancel.c:48)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050== Use of uninitialised value of size 8
==24050== at 0x4E3F0A0: pthread_cancel (pthread_cancel.c:102)
==24050== by 0x401106: main (main.c:232)
==24050==
==24050==
==24050== HEAP SUMMARY:
==24050== in use at exit: 816 bytes in 3 blocks
==24050== total heap usage: 14 allocs, 11 frees, 3,542 bytes allocated
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 1 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400EA4: main (main.c:137)
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 2 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400EE0: main (main.c:144)
==24050==
==24050== 272 bytes in 1 blocks are possibly lost in loss record 3 of 3
==24050== at 0x4C29E46: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==24050== by 0x4012084: _dl_allocate_tls (dl-tls.c:297)
==24050== by 0x4E3AABC: pthread_create@@GLIBC_2.2.5 (allocatestack.c:571)
==24050== by 0x400F1C: main (main.c:149)
==24050==
==24050== LEAK SUMMARY:
==24050== definitely lost: 0 bytes in 0 blocks
==24050== indirectly lost: 0 bytes in 0 blocks
==24050== possibly lost: 816 bytes in 3 blocks
==24050== still reachable: 0 bytes in 0 blocks
==24050== suppressed: 0 bytes in 0 blocks
==24050==
יש רעיונות?