thread 1 is main thread. I have a c++ code that executes in thread 2 ( my worker thread that I have spawned ). I would like to execute a native function in main thread and wait for the result
printf("I am on thread : %s", getthreadid());
int ret = executeOnMainWait(mynativefunc1("hello"));
printf("ret : %d", ret);
printf("I am on thread : %s", getthreadid());
bool b = executeOnMainWait(mynativefunc2(4, 5));
printf("b : %d", b);
int mynativefunc1(char* param) {
printf("mynativefunc1 I am on thread : %s", getthreadid());
if(strcmp(param, "hello")) {
return 1;
}
return 2;
}
bool mynativefunc2(int val1, int val2) {
printf("mynativefunc2 I am on thread : %s", getthreadid());
return (val1 + val2) == 5;
}
so this code should display :
I am on thread 2
mynativefunc1 I am on thread 1
ret : 1
I am on thread 2
mynativefunc2 I am on thread 1
b : true
I think we need to go to the java world through jni and use the handler and post something to main thread then wait it is complete, but the problem I don't know how to pass a function pointer directly with its own parameters. this example just show 2 native functions, but in reality I have 20. many thanks