Search Postgresql Archives

Threads With Libpq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Respected All,

This is my first request/post in PG-Generals. If it is not the place for these kind of queries, then please guide me where i need to be. 

I have a quick question regarding "pthread" with PostgreSQL 9.0 Libpq. I'm facing a problem with "Pthread" and libpq. Please find the below program behavoiur. 

Connection_To_PG()
{
/* Making a connection to PG 9.0 */
}

void* Independent_Thread1()
{
while(1)
{
sleep(5);
/* Doing 1 Insert Operation on Table A*/
}
}

void* Independent_Thread2()
{
while(1)
{
sleep(5);
/*Doing 1 Insert Operation on Table B*/
}

main()
{
pthread Ind1,Ind2;
Connection_TO_PG();
pthread_create(&Ind1,NULL,&Independent_Thread1,NULL);
pthread_create(&Ind2,NULL,&Independent_Thread2,NULL);
if(pthread_join(Ind1,NULL)<0)
{
printf("Ind1 is completed");
}
if(pthread_join(Ind2,NULL)<0)
{
printf("Ind2 is completed");
}
}


Problem Description:
====================
When i ran the above program, it's running(i.e inserting 2 to 10 records) some time and going to hang state. Some times, it's running more than 15 minutes and some times only 2 to 3 minutes. I enabled the postgresql log level to DEBUG5, and it's also stopped to showing the progress after 2 to 3 minutes span of time. 

Can some advise me, where i'm doing mistake in the above source code.. And would like to know to why it's not functioning properlly .. And i'm also getting the following message when the above libpq program runs..

******************* Message ********************
message type 0x31 arrived from server while idle
message type 0x32 arrived from server while idle
message type 0x6e arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle

However, the below sample thread(i.e without libpq) programg is working fine witout any issues.  

#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

void* thread1()
{
        while(1){
                printf("Thread1\n");
        }
}

void* thread2()
{
        while(1){
                printf("Thread2\n");
        }
}

int main()
{
        int status;
        pthread_t tid1,tid2;
        pthread_create(&tid1,NULL,&thread1,NULL);
        pthread_create(&tid2,NULL,&thread2,NULL);
        pthread_join(tid1,NULL);
        pthread_join(tid2,NULL);
        return 0;
}


Thanks in advance ... 

Best Regards,
Dinesh
manojadinesh.blogspot.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux