gthread memory allocation error

knightmanish knightmanish at gmail.com
Sun Nov 2 23:00:41 PST 2008


Hi, 
I'm using DBus with the dbus-glib integration. I am using asynchronous
binding and gthreads at server side (service side). Every new message
received by server is being handled in a new thread.
	I am noticing that virtual memory allocated to thread is not freed when it
terminates. On excessive use of server with large number of threads, it
produces an error

GThread-ERROR **: file /build/buildd/glib2.0-2.16.4/gthread/gthread-posix.c:
line 367 (g_thread_create_posix_impl): error 'Cannot allocate memory' during
'pthread_create'

aborting...

//This method is called on receiving of every message
static void
session_id(Echo *echo, gint32 position, DBusGMethodInvocation *context)
{
//checks for a free count value.
int i =0,count=-1;
	for(i=0;i<30;i++)
	{
		if (free_array[i].status==1)
		{	
			count=i;
			free_array[i].status=0;
			break;
		} 
			
	}
	if(count==-1)
	{
		printf("count = %d, dint get value assigned\n",count);
		exit(1);
	}

//stores the information in structure at particular count value to pass to
thread
//sessioid_array is a array of strucutre
// struct sessionid
// {
// DBusGMethodInvocation *context;
// int count;
// int position;
// };
sessionid_array[count].context = context;
sessionid_array[count].count = count;
sessionid_array[count].position = position;

//creates thread
if(!g_thread_create(session_id_thread,(gpointer)&sessionid_array[count],TRUE,&error))
	die ("Couldn't create thread from session id", error);
}

//this method is invoked for every thread 
static gpointer 
session_id_thread (gpointer data)
{
//restores information form structure
struct sessionid *my_data;
my_data = (struct sessionid *) data;
DBusGMethodInvocation *context = my_data->context;
int count = my_data->count;
int position_r = my_data->position;
char id[10]; 
strcpy(id,"test");

//returns the message to client 
dbus_g_method_return (context, id, position_r);

//frees the array position to be used by another thread
free_array[count].status=1;

//frees the memory
GThread* thread =  g_thread_self();
g_free(thread);
return NULL;
}

Am I missing some memory freeing function to be called OR something
necessary??

-- 
View this message in context: http://www.nabble.com/gthread-memory-allocation-error-tp20298022p20298022.html
Sent from the Free Desktop - dbus mailing list archive at Nabble.com.



More information about the dbus mailing list