ECPG still having thread problems on Linux - Mailing list pgsql-interfaces

From Lee Kindness
Subject ECPG still having thread problems on Linux
Date
Msg-id 16121.27884.841077.431930@kelvin.csl.co.uk
Whole thread Raw
In response to ECPG still having thread problems on Linux  (Philip Yarra <philip@utiba.com>)
Responses Re: ECPG still having thread problems on Linux
List pgsql-interfaces
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;

pgsql-interfaces by date:

Previous
From: The Hermit Hacker
Date:
Subject: libpgtcl and pgtclsh
Next
From: Philip Yarra
Date:
Subject: Re: ECPG still having thread problems on Linux