Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
threads.C File Reference

Detailed Description

Example of a simple script creating 3 threads.

This script can only be executed via ACliC: .x threads.C++. Before executing the script, load the Thread library with:

gSystem->Load("libThread");
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1857

This is not needed anymore due to the rootmap facility which automatically loads the needed libraries.

#include "TThread.h"
#include <Riostream.h>
void *handle(void *ptr)
{
long nr = (long) ptr;
for (int i = 0; i < 10; i++) {
TThread::Printf("Here I am loop index: %d , thread: %ld", i, nr);
gSystem->Sleep(10);
}
return 0;
}
void threads()
{
gDebug = 1;
printf("Starting Thread 1\n");
TThread *h1 = new TThread("h1", handle, (void*) 1);
h1->Run();
printf("Starting Thread 2\n");
TThread *h2 = new TThread("h2", handle, (void*) 2);
h2->Run();
printf("Starting Thread 3\n");
TThread *h3 = new TThread("h3", handle, (void*) 3);
h3->Run();
h1->Join();
h2->Join();
h3->Join();
}
Int_t gDebug
Definition TROOT.cxx:595
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
Definition TThread.h:40
static void Ps()
Static method listing the existing threads.
Definition TThread.cxx:843
static void Printf(const char *fmt,...)
Static method providing a thread safe printf. Appends a newline.
Definition TThread.cxx:916
TH1F * h1
Definition legend1.C:5
Author
Victor Perevovchikov

Definition in file threads.C.