List:General Discussion« Previous MessageNext Message »
From:Stefan Kuhn Date:November 7 2012 9:54pm
Subject:Re: UDF behaves non-deterministic
View as plain text  
Hi everybody,
it looks like the reason for the problem was me not handling  string arguments 
properly (I did not use the provided lengths, but relied on string being 
null-terminated, it's in the doc, but ...). It seems this became a problem 
specifically in the parallel situation, misleading me into believing it had 
to do with this. Thanks to everybody for help! Even though the solution was 
not directly provided, the comments made me think about my code and so were 
still helpfull.

On Monday 05 November 2012 15:08:51 Michael Dykman wrote:
> 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
> mutex.
>  - 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:

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