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


 

 



  김경남 부책임연구원
    
   솔루션사업본부 정보기술 연구원 
   신기술개발팀

    02-2099-6177 / 010-2208-3006

 



상기 메시지와 첨부화일 내에는 비밀정보가 포함되어 있을 수 있으며, 지정된 수신자에 한하여 조회 및 사용될 수 있습니다. 만약 송신자의 실수로 인하여 상기 메시지를 수신하였다면, 송신자에게 메시지를 반송해 주시고, 원본 메시지와 모든 사본을 폐기해 주시기 바랍니다.
상기 메시지의 전체 또는 일부에 대해 무단 열람, 사용, 공개, 배포하는 것은 금지되어 있습니다.(주)LG CNS.
This message and its attachments may contain confidential information, and they are intended to be viewed or used by only the individuals specified in the message. If you have received this message in an error from the sender, please contact the sender immediately to notify the error and delete all of the message and its copies. It is prohibited to view, use, make public and/or distribute part or whole of this message without written permission.