Re: Threads With Libpq - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Threads With Libpq
Date
Msg-id 64BE3FA9-F209-4AA0-A3FD-1F1FC87CAFA0@gmail.com
Whole thread Raw
In response to Threads With Libpq  (dinesh kumar <dineshkumar02@gmail.com>)
Responses Re: Threads With Libpq  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
On 1 Aug 2012, at 14:32, dinesh kumar wrote:

> 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
wherei need to be.  
>
> I have a quick question regarding "pthread" with PostgreSQL 9.0 Libpq. I'm facing a problem with "Pthread" and libpq.
Pleasefind 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");
> }
> }

You need a separate connection per thread or you need to synchronise your queries onto the single central connection,
meaningthat other threads need to be blocked (from performing queries) while any thread is performing a query. 

Alban Hertroys

--
Screwing up is an excellent way to attach something to the ceiling.


pgsql-general by date:

Previous
From: dinesh kumar
Date:
Subject: Threads With Libpq
Next
From: AI Rumman
Date:
Subject: Re: Where should I start for learn development