forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreads.C
More file actions
58 lines (49 loc) · 1.24 KB
/
threads.C
File metadata and controls
58 lines (49 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/// \file
/// \ingroup tutorial_thread
/// 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:
///
/// ~~~{.cpp}
/// gSystem->Load("libThread");
/// ~~~
///
/// This is not needed anymore due to the rootmap facility which
/// automatically loads the needed libraries.
///
/// \macro_code
///
/// \author Victor Perevovchikov
#include "TThread.h"
#include <Riostream.h>
void *handle(void *ptr)
{
long nr = (long) ptr;
for (int i = 0; i < 10; i++) {
//TThread::Lock();
//printf("Here I am loop index: %3d , thread: %d\n",i,nr);
//TThread::UnLock();
TThread::Printf("Here I am loop index: %d , thread: %ld", i, nr);
gSystem->Sleep(1000);
}
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();
TThread::Ps();
h1->Join();
TThread::Ps();
h2->Join();
h3->Join();
TThread::Ps();
}