Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* ============================================================================ Author : G. Barlas Version : 1.0 Last modified : December 2014 License : Released under the GNU GPL 3.0 Description : To

/* ============================================================================ Author : G. Barlas Version : 1.0 Last modified : December 2014 License : Released under the GNU GPL 3.0 Description : To compile : qmake debugSample.pro; make ============================================================================ */ #include #include #include #include #include #include

using namespace std;

#define DEBUG

//*********************************************** double time0 = 0; QMutex l; double hrclock () { timespec ts; clock_gettime (CLOCK_REALTIME, &ts); double aux = ts.tv_sec + ts.tv_nsec / 1000000000.0; return aux - time0; }

//*********************************************** void debugMsg (string msg, double timestamp) { l.lock (); cerr << timestamp << " " << msg << endl;* l.unlock (); }

//*********************************************** int counter = 0;

class MyThread:public QThread { private: int ID; int runs; public: MyThread (int i, int r):ID (i), runs (r) { } void run () { cout << "Thread " << ID << " is running "; for (int j = 0; j < runs; j++) { #ifdef DEBUG ostringstream ss; ss << "Thread #" << ID << " counter=" << counter; debugMsg (ss.str (), hrclock ()); #endif usleep (rand () % 3); counter++; } } };

int main (int argc, char *argv[]) { #ifdef DEBUG time0 = hrclock (); #endif

srand (time (0)); int N = atoi (argv[1]); int runs = atoi (argv[2]); MyThread *t[N]; for (int i = 0; i < N; i++) { t[i] = new MyThread (i, runs); t[i]->start (); }

for (int i = 0; i < N; i++) t[i]->wait ();

cout << counter << endl; return 0; } what are possible questions asked for a master exam from this code snippet

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago