maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #08397
Re: Using THD instance in a daemon thread.
Hi, 김경남!
You need to call
my_thread_init()
as early as possible in your new thread. And
my_thread_end()
Just before your thread ends.
Regards,
Sergei
On Mar 30, 김경남 wrote:
> Hi,
> I'm writing mariadb daemon type plugin.
> I hava a question.
>
> In a daemon thread, I want to use THD instance. for example,
>
> ------------------------------------------------------------------------
> -----------
> class THD;
> static int plugin_init() {
> ...
> pthread_create(&id,&attr,my_func,...);
> }
>
> void my_func(void* p)
> {
> THD* thd = new THD;
> thd->thread_stack= (char*) &thd;
> thd->store_globals();
> tables.init_one_table("performance_schema", 18,
> "events_statements_current", 25, "events_statements_current", TL_READ);
> open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT);
> ...
> }
>
> ------------------------------------------------------------------------
> --------------------
> but In my_func(), new THD cause error. I guess thread problem.
>
> So I moved that code to plugin_init() for test as below
>
> --------------------------------------------------------------
> class THD;
> static int plugin_init() {
> ...
> pthread_create(&id,&attr,my_func,...);
> THD* thd = new THD;
> thd->thread_stack= (char*) &thd;
> thd->store_globals();
> tables.init_one_table("performance_schema", 18,
> "events_statements_current", 25, "events_statements_current", TL_READ);
> open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT);
> ...
> }
> ------------------------------------------------------------------------
> -----
> and then there is no problem. but I need a daemon thread.
> I think that the reason of this error is assertion of thread. So I
> changed my code as below.
>
> ------------------------------------------------------------------------
> ---------
> class THD;
> THD* thd;
> static int plugin_init() {
> ...
> pthread_create(&id,&attr,my_func,...);
> THD* thd = new THD; // moved here from my_func() for avoiding error.
> }
>
> void my_func(void* p)
> {
> thd->thread_stack= (char*) &thd;
> thd->store_globals();
> tables.init_one_table("performance_schema", 18,
> "events_statements_current", 25, "events_statements_current", TL_READ);
> open_and_lock_tables(thd, &tables, FALSE, MYSQL_LOCK_IGNORE_TIMEOUT);
> ...
>
> }
> ------------------------------------------------------------------------
> -----------------
> At this time, thd->store_globals() cause error.
> In sql_class.cc , mysys_var->id= thread_id cause error because
> mysys_var is null.
>
>
> Let me know how to use THD instance in daemon thread.
>
> Regards,
> Kyungnam
>
References