//+ 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"); // This is not needed anymore due to the rootmap facility which // automatically loads the needed libraries. //Author: Victor Perevovchikov #include "TThread.h" #include #include #include #include #include #include #include TCanvas *c1; TGraph *gr; double pi(long int pHodu, double jehla=1, double pruh=1) { TRandom3 uhel(0); TRandom3 centrum(0); const double x=acos(0); int abc=0; double c, phi; int vyhovujici=0; for(abc=0; abc=1)) vyhovujici++; } if(vyhovujici==0) return 0; else return (2*(double)pHodu/(double)vyhovujici); //Odhad pi //return ((double)vyhovujici/(double)pHodu); //Odhad pravdepodobnosti } struct hodnoty { int N; double *x; double *b; hodnoty(int n){ N=n; b= new double[N]; x= new double[N]; for(int i=0; iN; i+=2) { tady->b[i]=pi(i); } return 0; } void *handle2(void *c) { hodnoty *tady = (hodnoty*) c; for (int k = 1; k < tady->N; k+=2) { tady->b[k]=pi(k); } return 0; } void threads() { TStopwatch stopky; stopky.ResetRealTime(); hodnoty test(100000); cout<Run(); printf("Starting Thread 2\n"); TThread *h2 = new TThread("h2", handle2, (void*)&test); h2->Run(); TThread::Ps(); h1->Join(); TThread::Ps(); h2->Join(); TThread::Ps(); TThread::Lock(); stopky.Stop(); c1 = new TCanvas("c1","",1024,800); gr = new TGraph(test.N,test.x,test.b); gr->GetXaxis()->SetTitle("N[-]"); //gr->Fit("pol1"); //fit pro presny odhad hodnoty pi, pouze u stejneho poctu hodu.. gr->Draw("ap"); c1->Modified(); c1->SaveAs("abc.pdf"); cout<