Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #5851
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: pthread memory leaks |
| Date | Tue, 31 May 2011 11:50:47 +1200 |
| Lines | 64 |
| Message-ID | <94ioqnFr2iU10@mid.individual.net> (permalink) |
| References | <9430fe32-d385-49a3-b925-daf3cd421789@j13g2000pro.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net 0v7HRZxURh8Tp6J23qiDVg/g7lU+CrfmRKliBJzAVBhyEDkigX |
| Cancel-Lock | sha1:GCuQIVYGdYArm7m+ZL+KES3h4z0= |
| User-Agent | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 |
| In-Reply-To | <9430fe32-d385-49a3-b925-daf3cd421789@j13g2000pro.googlegroups.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:5851 |
Show key headers only | View raw
On 05/31/11 11:29 AM, jakash3 wrote:
> I'm experimenting with signals and conditional variables to implement
> thread suspension. The following appears to execute without any
> problems but valgrind reports memory leaks.
> What can I do to stop the memory leaks? Is there some type of pthread
> related memory free function I'm forgetting?
You'd be better of on a Linux or Unix group for this kind of question.
However there are a few C++ specific issues:
> =================================
> #include<pthread.h>
> #include<signal.h>
> #include<unistd.h>
> #include<cstdio>
> #include<cstring>
> #include<cstdlib>
>
> pthread_mutex_t m;
> pthread_cond_t c;
>
> void freeze(int sig) {
> pthread_mutex_lock(&m);
> pthread_cond_wait(&c,&m);
> pthread_mutex_unlock(&m);
> }
> void quit(int sig) { pthread_exit(0); }
>
> void* tfunc(void* param) {
> while (1) {
> puts("hi");
As you have included the C++ versions of the C library headers, fictions
form them like puts should be written std::puts. Some compilers put
them in the namespace, while others (like gcc) declare them in and out
of the namespace, which is a pain.
> sleep(1);
> }
> return NULL;
> }
This are all assigned to C function pointers, so they should be declared
as extern "C" (gcc ignores this).
<snip code>
> valgrind output:
> =================================
> ==2993==
> ==2993== HEAP SUMMARY:
> ==2993== in use at exit: 144 bytes in 1 blocks
> ==2993== total heap usage: 1 allocs, 0 frees, 144 bytes allocated
> ==2993==
> ==2993== LEAK SUMMARY:
> ==2993== definitely lost: 0 bytes in 0 blocks
> ==2993== indirectly lost: 0 bytes in 0 blocks
> ==2993== possibly lost: 144 bytes in 1 blocks
Note this is an in use block, not an actual leak. Probably an internal
I/O buffer.
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
pthread memory leaks jakash3 <jakashthree@gmail.com> - 2011-05-30 16:29 -0700
Re: pthread memory leaks Ian Collins <ian-news@hotmail.com> - 2011-05-31 11:50 +1200
Re: pthread memory leaks Ian Collins <ian-news@hotmail.com> - 2011-05-31 11:52 +1200
Re: pthread memory leaks Puppet_Sock <puppet_sock@hotmail.com> - 2011-05-31 06:46 -0700
Re: pthread memory leaks jakash3 <jakashthree@gmail.com> - 2011-05-30 17:00 -0700
Re: pthread memory leaks Ian Collins <ian-news@hotmail.com> - 2011-05-31 12:02 +1200
Re: pthread memory leaks jakash3 <jakashthree@gmail.com> - 2011-05-30 17:05 -0700
Re: pthread memory leaks yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-06-06 09:38 +0000
Re: pthread memory leaks Stuart Redmann <DerTopper@web.de> - 2011-05-31 00:16 -0700
Re: pthread memory leaks "Chris M. Thomasson" <cristom@charter.net> - 2011-06-10 15:46 -0700
Re: pthread memory leaks Adam Skutt <askutt@gmail.com> - 2011-05-31 03:20 -0700
Re: pthread memory leaks Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-06-01 08:27 +0000
Re: pthread memory leaks Miles Bader <miles@gnu.org> - 2011-06-01 17:39 +0900
Re: pthread memory leaks Ian Collins <ian-news@hotmail.com> - 2011-06-01 21:05 +1200
Re: pthread memory leaks Adam Skutt <askutt@gmail.com> - 2011-06-01 03:27 -0700
Re: pthread memory leaks Adam Skutt <askutt@gmail.com> - 2011-06-01 03:16 -0700
csiph-web