unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Memory leak with threads + guile 1.8.7 ?
@ 2010-09-15 13:47 Cedric Cellier
  2011-02-12 14:20 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Cedric Cellier @ 2010-09-15 13:47 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

Hello dear hackers !

I'm using guile in an C program that spawn a lot of short lived
threads, each of which passing in guile mode (guile 1.8.7), and I'm
facing a memory leak even when the threads does nothing (ie. the
C function called by scm_with_guile consists only of a return NULL.
After some time, if I call a gc-stats I have many many segments of
21Mb allocated, although gc-live-object-stats reports that almost
nothing is alive (acording to expectations).

I am under the impression that some of these segments, created by a
now defunct thread, can not be reused by others.

So I made a small program that continuously creates thread and run
a NOP scm_with_guile in it, and then join it (so that thre thread local
storage itself is not leaked).

With the useless scm_with_guile call, this programm leaks memory
very quickly. Comment out the scm_with_guile call and there is no more
leak.

What do you think ?


[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 173 bytes --]

CFLAGS += $(shell guile-config compile) -std=c99
CPPFLAGS += -D_GNU_SOURCE
LDLIBS += $(shell guile-config link) -lpthread

all: many_threads

clean:
	rm -f *.o many_threads

[-- Attachment #3: many_threads.c --]
[-- Type: text/x-csrc, Size: 486 bytes --]

#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <libguile.h>

static void *thread_with_guile(void *null)
{
    return NULL;
}

static void *the_thread(void *args)
{
    (void)scm_with_guile(thread_with_guile, NULL);	// comment me to remove the memory leak
    return NULL;
}


int main(void)
{
	// We create many threads
	while (1) {
	    pthread_t ptid;
    	pthread_create(&ptid, NULL, the_thread, NULL);
		void *ret;
		pthread_join(ptid, &ret);
	}

	return 0;
}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-12 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-15 13:47 Memory leak with threads + guile 1.8.7 ? Cedric Cellier
2011-02-12 14:20 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).