// This script can only be executed via ACliC .x Interrupt_Thread.C++. #include "TApplication.h" #include "TSystem.h" #include "TGButton.h" #include "TThread.h" TThread *th1 = 0; const char symb[] = {'|','/','-','\\',0}; void *JobThread(void *) { // this is the thread function actually doing the real job, // allowing the main thread to process events int i = 0; printf("\n"); while (1) { gSystem->Sleep(50); printf("%c\r", symb[i]); if (!symb[++i]) i = 0; } return 0; } void DoStart() { // if the thread has been created and is not running, start it if (th1 && th1->GetState() != TThread::kRunningState) th1->Run(); } void DoStop() { // if the thread has been created and is running, kill it if (th1 && th1->GetState() == TThread::kRunningState) th1->Kill(); } void Interrupt_Thread() { #ifdef __CINT__ printf("This script can only be executed via ACliC: .x Interrupt_Thread.C++\n"); return; #endif // create the thread for the job th1 = new TThread("th1", JobThread); // main frame TGMainFrame *fMainFrame = new TGMainFrame(gClient->GetRoot(),10,10); fMainFrame->SetWindowName("Test Interrupt"); // horizontal frame TGHorizontalFrame *fHFrame = new TGHorizontalFrame(fMainFrame,200,100); TGTextButton *fStart = new TGTextButton(fHFrame,"Start"); fStart->Resize(100, 100); fStart->Connect("Clicked()",0,0,"DoStart()"); fHFrame->AddFrame(fStart, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); TGTextButton *fStop = new TGTextButton(fHFrame,"Stop"); fStop->Resize(100,100); fStop->Connect("Clicked()",0,0,"DoStop()"); fHFrame->AddFrame(fStop, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); fMainFrame->AddFrame(fHFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2)); fMainFrame->MapSubwindows(); fMainFrame->Resize(fMainFrame->GetDefaultSize()); fMainFrame->MapWindow(); fMainFrame->Resize(220,110); }