From: Michael Widenius Date: May 4 2011 11:52am Subject: Re: Use of thread specific data with mysqld List-Archive: http://lists.mysql.com/internals/38317 Message-Id: <19905.15869.598814.144718@narttu.askmonty.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi! >>>>> "Mats" == Mats Kindahl writes: Mats> On 04/28/2011 02:41 AM, Hiromichi Watari wrote: >> Hi Marc, >> Thank you very much for your pointer, I believe I'm OK with my data residing in struct st_my_thread_var with the common key THR_KEY_mysys for now. However if the need changes in the future I will definitely take a look at what you have done. I appreciate you taking time to answer my question. >> Hiromichi Mats> Hi Hiromichi, Mats> A general note on storing data for a thread using pthread_setspecific Mats> in MySQL: it only works if there is a single THD associated with each Mats> thread. There were, for example, an experimental thread pool Mats> implementation in an 6.0 of the server trees where each POSIX thread Mats> managed several THD "session threads". If this architecture is used, Mats> it means that thread-specific data set using pthread_setspecific can Mats> "leak" to a different session if the same thread switches to use a Mats> different THD structure. Mats> This is not the case unless you use 6.0, but since that never GA:ed, Mats> it should not be a problem in production environments since the 5.1 Mats> server has one THD structure for each POSIX thread. In MariaDB there is the option to run with thread pool and as far as I know, there is also in the plans to release a tread pool for MySQL enterprise (but not for the community server). With the thread pool, you can however be sure that the thread may only change between two queries, not during a query. (This may change when we start to add parallel execution of queries). In addition, the following thread objects will on thread switch be copied to point to the relevant objects: THR_THD THR_MALLOC If you want to store connection specific information, you should store them in THD, not in THR_KEY_mysys ! Regards, Monty