[HACKERS] Is ECPG's SET CONNECTION really not thread-aware? - Mailing list pgsql-hackers

From Tsunakawa, Takayuki
Subject [HACKERS] Is ECPG's SET CONNECTION really not thread-aware?
Date
Msg-id 0A3221C70F24FB45833433255569204D1F71CE45@G01JPEXMBYT05
Whole thread Raw
Responses Re: [HACKERS] Is ECPG's SET CONNECTION really not thread-aware?
List pgsql-hackers
Hello,

The following page says:

https://www.postgresql.org/docs/devel/static/ecpg-connect.html#ecpg-set-connection

--------------------------------------------------
EXEC SQL AT connection-name SELECT ...;

If your application uses multiple threads of execution, they cannot share a connection concurrently. You must either
explicitlycontrol access to the connection (using mutexes) or use a connection for each thread. If each thread uses its
ownconnection, you will need to use the AT clause to specify which connection the thread will use.
 

EXEC SQL SET CONNECTION connection-name;

...It is not thread-aware.
--------------------------------------------------


What does this mean by "not thread-aware?"  Does SET CONNECTION in one thread change the current connection in another
thread?
It doesn't look so, because the connection management and SQL execution in ECPG uses thread-specific data (TSD) to get
andset the current connection, like this:
 


bool
ECPGsetconn(int lineno, const char *connection_name)
{   struct connection *con = ecpg_get_connection(connection_name);
   if (!ecpg_init(con, connection_name, lineno))       return (false);

#ifdef ENABLE_THREAD_SAFETY   pthread_setspecific(actual_connection_key, con);
#else   actual_connection = con;
#endif   return true;
}

Regards
Takayuki Tsunakawa




pgsql-hackers by date:

Previous
From: Dilip Kumar
Date:
Subject: Re: [HACKERS] Error while creating subscription when server isrunning in single user mode
Next
From: Michael Paquier
Date:
Subject: Re: [HACKERS] Error while creating subscription when server isrunning in single user mode