From: Hiromichi Watari Date: April 26 2011 7:19pm Subject: Re: Use of thread specific data with mysqld List-Archive: http://lists.mysql.com/internals/38310 Message-Id: <612015.4910.qm@web121520.mail.ne1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi Sergei, I tried but I just couldn't make my own thread specific data to coexist wit= h structure st_my_thread_var so I ended up moving my data to the structure = and used it instead. I suppose there is really no reason to reinvent the wheel, is there ? But anyway, thank you for your help and you are the best. Hiromichi --- On Sun, 4/24/11, Sergei Golubchik wrote: > From: Sergei Golubchik > Subject: Re: Use of thread specific data with mysqld > To: "Hiromichi Watari" > Cc: internals@stripped > Date: Sunday, April 24, 2011, 5:04 PM > Hi, Hiromichi! >=20 > 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 > >=20 > > p.s. I ran into this problem only if I try to use my > own thread specific data, of course. >=20 > probably you forgot to call my_thread_init() in the > beginning of your > thread function. >=20 > Anyway, here's the code: >=20 > #define my_errno my_thread_var->thr_errno >=20 > #define my_thread_var (_my_thread_var()) >=20 > struct st_my_thread_var *_my_thread_var(void) > { > =A0 return=A0 my_pthread_getspecific(struct > st_my_thread_var*,THR_KEY_mysys); > } >=20 > my_bool my_thread_init(void) > { > =A0 ... > =A0 =A0 if (!(tmp=3D (struct st_my_thread_var *) > calloc(1, sizeof(*tmp)))) > =A0 =A0 { > =A0 =A0 =A0 error=3D 1; > =A0 =A0 =A0 goto end; > =A0 =A0 } > =A0 =A0 pthread_setspecific(THR_KEY_mysys,tmp); > =A0 ... > } >=20 > Regards, > Sergei >