MySQL Forums
Forum List  »  UDF

Using pthread_mutex in UDF
Posted by: Carl Duisberg
Date: September 09, 2011 03:58PM

For some user defined functions it is necessary to use static storage. Static storage has to be protected my pthread mutexes to keep the UDF library thread safe. A scheme that has been followed by some developers is:

my_bool udf_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
pthread_mutex_init(&LOCK, 0);
void udf_deinit(UDF_INIT *initid __attribute__((unused)))
(void) pthread_mutex_destroy(&LOCK);

I guess this is unsafe. If two SQL queries use the same user defined function at the same time, the queries may be handled by separate threads.

Where is the right place to put the code to initialize and destroy mutexes?

One idea I have on my mind, is to declare the library as a plugin and to use the plugin initialization and deintialization routines to handle initialization and destruction of mutexes. Unfortunately there is no documentation available for UDF plugins. Hence I am thinking about declaring the library to be a daemon plugin.

Is this an appropriate approach?

Options: ReplyQuote

Written By
Using pthread_mutex in UDF
September 09, 2011 03:58PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.