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 <stef...@web.de> 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.
> >
> >http://dev.mysql.com/doc/refman/5.5/en/adding-udf.html
> >
> >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
> dnel...@allantgroup.com
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql
>
>


-- 
 - michael dykman
 - mdyk...@gmail.com

 May the Source be with you.

Reply via email to