-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
Most probably I missed something.
I have problems with threads cleanup. Here are output of valgrind and
simple test program:
...
==78317== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==78317== malloc/free: in use at exit: 4108 bytes in 2 blocks.
==78317== malloc/free: 5 allocs, 3 frees, 4324 bytes allocated.
==78317===78317== searching for pointers to 2 not-freed blocks.
==78317== checked 1468040 bytes.
==78317===78317== 12 bytes in 1 blocks are still reachable in loss record 1 of 2
==78317== at 0x3C038183: malloc (in
/usr/local/lib/valgrind/vgpreload_memcheck.so)
==78317== by 0x3C03F8D0: (within /usr/local/lib/valgrind/libthr.so.2)
==78317== by 0x3C040F49: pthread_mutex_init (in
/usr/local/lib/valgrind/libthr.so.2)
==78317== by 0x3C040FA9: pthread_mutex_lock (in
/usr/local/lib/valgrind/libthr.so.2)
==78317===78317===78317== 4096 bytes in 1 blocks are still reachable in loss
record 2 of 2
==78317== at 0x3C038183: malloc (in
/usr/local/lib/valgrind/vgpreload_memcheck.so)
==78317== by 0x3C121AE5: __smakebuf (in /lib/libc.so.6)
==78317== by 0x3C1219B0: __swsetup (in /lib/libc.so.6)
==78317== by 0x3C11789B: __vfprintf (in /lib/libc.so.6)
...
#include <stdio.h>
#include <pthread.h>
void *Worker(void * flags)
{
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
printf("Worker started!\n");
sleep(1);
printf("Worker finiched!\n");
*(int *)flags = 1;
for(;;) {
printf("pthread_testcancel()!\n");
pthread_testcancel();
sleep(1);
}
}
int main()
{
pthread_t tid, tid2;
void * arg;
arg = (int *)malloc(sizeof(int));
*(int *)arg = 0;
pthread_create(&tid, NULL, Worker, arg);
for(;;) {
if(*(int *)arg) {
printf("pthread_cancel()!\n");
pthread_cancel(tid);
free(arg);
pthread_exit((void *)0);
}
sleep(1);
}
}
Any hints?
Best Regards
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)
iD8DBQFIEE0UxJBWvpalMpkRAjluAKCpkMLNnK5+/Wwz0jAmdnqi6O1zyACeNf1F
kJHy5JX5fLb3rLFwq/Mis74=oBmp
-----END PGP SIGNATURE-----