Thread: safety of siglongjmp

  1. #1
    Registered User
    Join Date
    Aug 2002

    safety of siglongjmp


    i need to set a timeout on a mysql_query, and believe it or not, there is no built in function to do this in the mysql c api.

    so, i thought about using a simple alarm signal around the mysql_query call - this didn't work.

    with some searching on the web i found this solution: (quote)

    For now the only solution I know of is this (in C):

    - establish connection
    - remember connection id
    - signal(SIGALRM, got_bored_waiting);
    - alarm(10);
    - do your query
    - in your alarm handler (got_bored_waiting) use siglongjmp() to jump out of the trap
    - after your query call sigsetjmp()
    - test the return value -- if sigsetjmp() tells you your are there because you
    timed out, establish another connection and do mysql_kill_thread on your old connection id to clean up and to make sure you still have the connection
    - don't forget to alarm(0)

    now this seems ok, but i also found a answer to the same suggestion elsewhere that described the safety of siglongjmp as questionable.

    does anyone know about siglongjmp and its safety in this context?

    TIA, rotis23

  2. #2
    Registered User
    Join Date
    Aug 2002
    thanks, i've just read about sig_atomic_t. should i use this type for all flags set in a signal handler?

    mysql_query(MYSQL *mysql,char *query);

    is part of the mysql c api. its a real pain in the a*se to use sometimes (the whole api). there is a problem where if the mysql server hangs (or any other reason to break the network connection), it causes the client to hang because the client has no query timeout (it eventually times out to a TCP timeout - i think 15min).

    i can't use a standard signal alarm because its stopped/handled somewhere in the depths of mysql_query.

    the response above is actually provided by one of the mysql developers on the archived mailling list. i was just concerned about using siglongjmp - sounds like goto to me!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. thread safety in ManualResetEvent
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-16-2008, 08:06 AM
  2. thread safety using Interlocked
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-16-2008, 03:07 AM
  3. global variables and thread safety
    By laertius in forum C Programming
    Replies: 11
    Last Post: 07-18-2006, 10:43 AM
  4. MFC Controls and Thread Safety :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 12-06-2002, 11:36 AM
  5. Escape to Safety
    By TechWins in forum Game Programming
    Replies: 10
    Last Post: 04-26-2002, 08:08 AM