How do I terminate the script by using the API G__calc?

Hi Everyone,

I used the CINT interpreter, it’s very convenient for me.
But I have a question for how to terminate the script that is running by API G__calc?

My programming source code is running the G__calc in a thread like:


My script likes:
while(1) {


Now, I only use the dangerous API “TerminateThread” to terminte the script, but it always memory leaks :cry:

Dose anybody suggest me how to resolve the question?




What about simply using ‘return’? (Or maybe exit if you want to also end the process).


Because the code is blocking while running the C script file by the API G__calc, I do not have any method to notify the C script “return”; I only used the TerminateThread to terminate the running thread :frowning:


you could share a variable, say “int terminateThread” with G__calc. You pass it into G__calc as the address to the variable, i.e.

int terminateThread = 0;
char buf[1024];
sprintf(buf, "main((int*)%ld)", &terminateThread);

main() now becomes:

main(int* pTerminateThread) {
while(!*pTerminateThread) {

You end G__calc by simply setting int terminateThread = 1. There is an issue with the two threads accessing the same memory address without synchronization, but really, you don’t care :slight_smile:

Cheers, Axel.