List:General Discussion« Previous MessageNext Message »
From:Michael Dykman Date:November 5 2012 3:08pm
Subject:Re: Re: UDF behaves non-deterministic
View as plain text  
C is not an inherently thread-safe language.  Several of the standard
library functions use static data, which gets stepped on during concurrent
operation.  Many of those do have thread-safe equivalents on many platforms
such as strtok/strtok_r (the latter being the safe one).

If you are confident you are not using statics or globals in your code
directly, you will need to identify each function you do call.  Start by
reading the man page for that function (if it's in the C stdlib, there is a
man page for it) which should tell you if it is safe or not; for those
which are not, the man page will likely suggest a threadsafe alternative if
one is available.  If none are available, you might have to consider a

 - michael dykman

On Mon, Nov 5, 2012 at 9:28 AM, Stefan Kuhn <stefhk3@stripped> wrote:

> Hi Dan,
> thanks for your answer. The UDF only contains functions (the one called in
> sql plus two functions called in it). There are no variables outside them
> and nothing is declared static. All variables inside the functions are
> declared just like "double x=0;" etc. I am not an expert on C, but my
> understanding is that these values are separate for each call of the
> function and don't influence each other. Do you have a suggestion what I
> should look for in my c code? Or do I need to make the code thread-safe in
> that sense that concurrent executions are prevented by monitors or
> semaphors or so (no idea about what this is called in c)?
> Stefan
> >The first thing I would do is examine your UDF and ensure that it is
> >thread-safe. No global variables, no static variables within functions,
> >etc. Also make sure that any libc functions you call that are documented
> as
> >non-threadsafe are wrapped by a mutex or otherwise protected against
> >multiple simultaneous access.
> >
> >
> >
> >As for debugging, you should be able to write things to stderr which will
> >show up in the mysql logfile, or you could open your own logfile and write
> >to that.
> --
> Dan Nelson
> dnelson@stripped
> --
> MySQL General Mailing List
> For list archives:
> To unsubscribe:

 - michael dykman
 - mdykman@stripped

 May the Source be with you.

Aw: Re: UDF behaves non-deterministicStefan Kuhn5 Nov
  • Re: Re: UDF behaves non-deterministicMichael Dykman5 Nov
    • Re: UDF behaves non-deterministicStefan Kuhn7 Nov