ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
threads.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_thread
3
/// Example of a simple script creating 3 threads.
4
/// This script can only be executed via ACliC: .x threads.C++.
5
/// Before executing the script, load the Thread library with:
6
///
7
/// ~~~{.cpp}
8
/// gSystem->Load("libThread");
9
/// ~~~
10
///
11
/// This is not needed anymore due to the rootmap facility which
12
/// automatically loads the needed libraries.
13
///
14
/// \macro_code
15
///
16
/// \author Victor Perevovchikov
17
18
#include "
TThread.h
"
19
#include <
Riostream.h
>
20
21
void
*handle(
void
*ptr)
22
{
23
long
nr = (long) ptr;
24
25
for
(
int
i
= 0;
i
< 10;
i
++) {
26
TThread::Printf
(
"Here I am loop index: %d , thread: %ld"
,
i
, nr);
27
gSystem
->Sleep(10);
28
}
29
return
0;
30
}
31
32
void
threads()
33
{
34
35
gDebug
= 1;
36
37
printf(
"Starting Thread 1\n"
);
38
TThread
*
h1
=
new
TThread
(
"h1"
, handle, (
void
*) 1);
39
h1
->Run();
40
printf(
"Starting Thread 2\n"
);
41
TThread
*
h2
=
new
TThread
(
"h2"
, handle, (
void
*) 2);
42
h2
->Run();
43
printf(
"Starting Thread 3\n"
);
44
TThread
*
h3
=
new
TThread
(
"h3"
, handle, (
void
*) 3);
45
h3
->Run();
46
47
TThread::Ps
();
48
49
h1
->Join();
50
TThread::Ps
();
51
h2
->Join();
52
h3
->Join();
53
TThread::Ps
();
54
}
Riostream.h
i
Int_t i
Definition
TGraphAsymmErrors.cxx:1306
gDebug
Int_t gDebug
Definition
TROOT.cxx:622
gSystem
R__EXTERN TSystem * gSystem
Definition
TSystem.h:566
TThread.h
TThread
<div class="legacybox"><h2>Legacy Code</h2> TThread is a legacy interface: there will be no bug fixes...
Definition
TThread.h:40
TThread::Ps
static void Ps()
Static method listing the existing threads.
Definition
TThread.cxx:843
TThread::Printf
static void Printf(const char *fmt,...)
Static method providing a thread safe printf. Appends a newline.
Definition
TThread.cxx:916
h1
TH1F * h1
Definition
legend1.C:5
TMVA_SOFIE_GNN_Parser.h2
h2
Definition
TMVA_SOFIE_GNN_Parser.py:188
TMVA_SOFIE_GNN_Parser.h3
h3
Definition
TMVA_SOFIE_GNN_Parser.py:189
tutorials
legacy
thread
threads.C
ROOT v6-32 - Reference Guide Generated on Sun May 17 2026 02:44:15 (GVA Time) using Doxygen 1.13.2