threads.C

Go to the documentation of this file.
00001 //+ Example of a simple script creating 3 threads.
00002 // This script can only be executed via ACliC: .x threads.C++.
00003 // Before executing the script, load the Thread library with:
00004 //   gSystem->Load("libThread");
00005 // This is not needed anymore due to the rootmap facility which
00006 // automatically loads the needed libraries.
00007 //Author: Victor Perevovchikov
00008    
00009 #include "TThread.h"
00010 #include <Riostream.h>
00011 
00012 void *handle(void *ptr)
00013 {
00014    long nr = (long) ptr;
00015 
00016    for (int i = 0; i < 10; i++) {
00017       //TThread::Lock();
00018       //printf("Here I am loop index: %3d , thread: %d\n",i,nr);
00019       //TThread::UnLock();
00020 
00021       TThread::Printf("Here I am loop index: %d , thread: %ld", i, nr);
00022       gSystem->Sleep(1000);
00023    }
00024    return 0;
00025 }
00026 
00027 void threads()
00028 {
00029 #ifdef __CINT__
00030    printf("This script can only be executed via ACliC: .x threads.C++\n");
00031    return;
00032 #endif
00033 
00034    gDebug = 1;
00035 
00036    printf("Starting Thread 1\n");
00037    TThread *h1 = new TThread("h1", handle, (void*) 1);
00038    h1->Run();
00039    printf("Starting Thread 2\n");
00040    TThread *h2 = new TThread("h2", handle, (void*) 2);
00041    h2->Run();
00042    printf("Starting Thread 3\n");
00043    TThread *h3 = new TThread("h3", handle, (void*) 3);
00044    h3->Run();
00045 
00046    TThread::Ps();
00047 
00048    h1->Join();
00049    TThread::Ps();
00050    h2->Join();
00051    h3->Join();
00052    TThread::Ps();
00053 }

Generated on Tue Jul 5 15:45:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1