pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lee Kindness <lkindness@csl.co.uk>
To: Philip Yarra <philip@utiba.com>
Cc: Lee Kindness <lkindness@csl.co.uk>
Cc: pgsql-interfaces@postgresql.org
Subject: ECPG still having thread problems on Linux
Date: Wed, 25 Jun 2003 10:35:40 +0100
Message-ID: <16121.27884.841077.431930@kelvin.csl.co.uk> (raw)
In-Reply-To: <200306241825.32527.philip@utiba.com>
References: <200306241825.32527.philip@utiba.com>

Philip, both your SELECTs are using the same database connection (and
it's undefined which one it is) without any locking. You need to add
"AT clauses" to specify an explicit connection. See attached diff.

However, i've not tried it... I'll try and get some time!

L.

Philip Yarra writes:
 > Hi all, it looks like Lee's ECPG (and libpq) thread-safety patches
 > have been applied, and configure --with-threads is also added. I
 > have been doing some testing.
 > 
 > On FreeBSD 4.8, the attached sample app runs without a problem.
 > 
 > However, I still encounter a threading problem on Linux (RedHat 7.3).
 > 
 > I have done the following:
 > 1) cvs update
 > 2) ./configure --with-threads && make && su -c "make install"
 > 3) compiled cn.pgc as follows:
 >         a) ecpg -t cn.pgc
 >         b) gcc -I/usr/local/pgsql/include -L/usr/local/pgsql/lib \
 >                 -lecpg -lpgtypes -pthread cn.c
 > 4) ./a.out - one thread runs to completion (inserts 5 records),
 >         the other hangs (manages one insert, then blocks forever)
*** cn.pgc	2003-06-25 10:29:55.000000000 +0100
--- cn.pgc.new	2003-06-25 10:29:45.000000000 +0100
***************
*** 36,46 ****
  	EXEC SQL END DECLARE SECTION;
  	EXEC SQL WHENEVER sqlerror sqlprint;
  	EXEC SQL CONNECT TO :cs AS test1;
! 	EXEC SQL SET AUTOCOMMIT TO ON;
  	for (i = 0; i < 5; i++)
  	{
  		printf("thread1 inserting\n");
! 		EXEC SQL INSERT INTO foo VALUES(:bar);
  		printf("==>thread1 insert done\n");
  	}
  	EXEC SQL DISCONNECT test1;
--- 36,46 ----
  	EXEC SQL END DECLARE SECTION;
  	EXEC SQL WHENEVER sqlerror sqlprint;
  	EXEC SQL CONNECT TO :cs AS test1;
! 	EXEC SQL AT test1 SET AUTOCOMMIT TO ON;
  	for (i = 0; i < 5; i++)
  	{
  		printf("thread1 inserting\n");
! 		EXEC SQL AT test1 INSERT INTO foo VALUES(:bar);
  		printf("==>thread1 insert done\n");
  	}
  	EXEC SQL DISCONNECT test1;
***************
*** 57,67 ****
  	EXEC SQL END DECLARE SECTION;
  	EXEC SQL WHENEVER sqlerror sqlprint;
  	EXEC SQL CONNECT TO :cs AS test2;
! 	EXEC SQL SET AUTOCOMMIT TO ON;
  	for (i = 0; i < 5; i++)
  	{
  		printf("thread2 inserting\n");
! 		EXEC SQL INSERT INTO foo VALUES(:bar);
  		printf("==>thread2 insert done\n");
  	}
  	EXEC SQL DISCONNECT test2;
--- 57,67 ----
  	EXEC SQL END DECLARE SECTION;
  	EXEC SQL WHENEVER sqlerror sqlprint;
  	EXEC SQL CONNECT TO :cs AS test2;
! 	EXEC SQL AT test2 SET AUTOCOMMIT TO ON;
  	for (i = 0; i < 5; i++)
  	{
  		printf("thread2 inserting\n");
! 		EXEC SQL AT test2 INSERT INTO foo VALUES(:bar);
  		printf("==>thread2 insert done\n");
  	}
  	EXEC SQL DISCONNECT test2;

Attachments:

cn.pgc.diff (text/plain, 1.5K) download *** cn.pgc 2003-06-25 10:29:55.000000000 +0100 --- cn.pgc.new 2003-06-25 10:29:45.000000000 +0100 *************** *** 36,46 **** EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER sqlerror sqlprint; EXEC SQL CONNECT TO :cs AS test1; ! EXEC SQL SET AUTOCOMMIT TO ON; for (i = 0; i < 5; i++) { printf("thread1 inserting\n"); ! EXEC SQL INSERT INTO foo VALUES(:bar); printf("==>thread1 insert done\n"); } EXEC SQL DISCONNECT test1; --- 36,46 ---- EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER sqlerror sqlprint; EXEC SQL CONNECT TO :cs AS test1; ! EXEC SQL AT test1 SET AUTOCOMMIT TO ON; for (i = 0; i < 5; i++) { printf("thread1 inserting\n"); ! EXEC SQL AT test1 INSERT INTO foo VALUES(:bar); printf("==>thread1 insert done\n"); } EXEC SQL DISCONNECT test1; *************** *** 57,67 **** EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER sqlerror sqlprint; EXEC SQL CONNECT TO :cs AS test2; ! EXEC SQL SET AUTOCOMMIT TO ON; for (i = 0; i < 5; i++) { printf("thread2 inserting\n"); ! EXEC SQL INSERT INTO foo VALUES(:bar); printf("==>thread2 insert done\n"); } EXEC SQL DISCONNECT test2; --- 57,67 ---- EXEC SQL END DECLARE SECTION; EXEC SQL WHENEVER sqlerror sqlprint; EXEC SQL CONNECT TO :cs AS test2; ! EXEC SQL AT test2 SET AUTOCOMMIT TO ON; for (i = 0; i < 5; i++) { printf("thread2 inserting\n"); ! EXEC SQL AT test2 INSERT INTO foo VALUES(:bar); printf("==>thread2 insert done\n"); } EXEC SQL DISCONNECT test2;

view thread (3+ messages)  latest in thread

Message-ID: <16121.27884.841077.431930@kelvin.csl.co.uk>
Permalink:  ../16121.27884.841077.431930@kelvin.csl.co.uk/
Also on:    postgresql.org/message-id/16121.27884.841077.431930@kelvin.csl.co.uk

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: lkindness@csl.co.uk, philip@utiba.com
  Subject: Re: ECPG still having thread problems on Linux
  In-Reply-To: <16121.27884.841077.431930@kelvin.csl.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox