Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
511 B
1
Indexable
Never
#include <iostream>
#include <cmath>
#include <thread>
#include <mutex>
using namespace std;
void rrenja_katrore(int numri, mutex& mtx)
{
    mtx.lock();
    cout<<"Rrenja katrore e "<<numri<<" eshte "<<sqrt(numri)<<endl;
    mtx.unlock();
}
int main ()
{
  int numrat[5]={25,36,49,64,81};
  thread threads[5];
  mutex mtx;
  int i;
  for(i=0;i<5;i++)
  {
      threads[i]=thread(rrenja_katrore,numrat[i],ref(mtx));
  }
  for(i=0;i<5;i++)
  {
    threads[i].join();
  }
  return 0;
}
Leave a Comment