Hi, Hiromichi!
On Apr 24, Hiromichi Watari wrote:
> Hi,
> I'm trying to use thread specific data with mysqld but ran into a problem with
> my_errno generating Segmentation fault at the following line.
> I know that my_errno is also thread specific data but not familiar with its
> implementation.
> I'm using pthread_key_create(), pthread_setspecific() and pthread_getspecific() for
> my own thread specific data, is there something I should be aware of ?
> Thanks,
> Hiromichi
>
> p.s. I ran into this problem only if I try to use my own thread specific data, of
> course.
probably you forgot to call my_thread_init() in the beginning of your
thread function.
Anyway, here's the code:
#define my_errno my_thread_var->thr_errno
#define my_thread_var (_my_thread_var())
struct st_my_thread_var *_my_thread_var(void)
{
return my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys);
}
my_bool my_thread_init(void)
{
...
if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp))))
{
error= 1;
goto end;
}
pthread_setspecific(THR_KEY_mysys,tmp);
...
}
Regards,
Sergei