On 25 February 2013 16:48, [email protected] <[email protected]> wrote:
>
> As a follow up to the thread safety "thread" I would like to request a
> cancel operation as a thread "semi safe" operation.
>
> I use the following cancel operation (PostgreSQL only). I have no idea if
> this or something similar will work for other backends ?

AFAIK, it is possible for DB2 using SQLCancel() function.

> Also I have no firm knowledge that the implementation is correct, but it
> does seem to work when called from another thread. Notice the
> soci::session object must exist and be valid for the duration of the call.
> But no ongoing SQL operation is required.
>
> void cancel( soci::session & _session )
> {
>     details::session_backend *p = _session.get_backend();
>     // using dynamic_cast instead of static_cast to allow conversion to
> other backends.
>     postgresql_session_backend *pp =
> dynamic_cast<postgresql_session_backend*>(p);
>     if (pp)
>     {
>         PGcancel *pgc = PQgetCancel( pp->conn_ );
>         if ( pgc )
>         {
>             char buffer[257];
>             memset(buffer,0,257);
>             int result = PQcancel( pgc, buffer, 256 );
>             PQfreeCancel(pgc);
>             if ( result ) {}
>         }
>     }
> }

The implementation is correct, but it is thread-safe, not guaranteed
as such by SOCI.
Unless, either you make it thread safe or you guarantee that the
_session object has
been obtained using the pool-dedicated constructor of soci::session

session sql(pool);
cancel(sql);

as per phase 2 here: http://soci.sourceforge.net/doc/multithreading.html

ATM, I don't have time to discuss this solution myself.
Feel free to open feature request issue at GitHub, copy your code and
explain exactly how your scenario performs call to this cancel() function.

Should such non-trivial feature be added to SOCI (whoever implements it),
I would ask for pull request or issue ticket at GitHub anyway.
It would also be useful to make there a list of cancelling options available
for other backends.

The more details are collected, the better the picture and the higher chances
that someone will be interested to work on it.
Any such collection at GitHub, please.

Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to