class VM
{
private:
pthread_t tid;
float fUtil;
public:
int iVID;
struct timeval start;
vdata_t vdata;
public:
VM(void);
VM(int vid,int sid);
~VM(void);
int EnqJob(job_t job);
int Run(void);
static void* WorkingVM(void* data);
float GetUtil(void);
};
I put the working thread function (WorkingVM) in the class.
This VM class has a job queue. Outside of this class calls EnqJob() to push jobs, and WorkingVM will pop the queue, and handle the jobs.
So, I need a mutex on the job queue.
The problem is that it is impossible to access vdata from the thread function(WorkingVM). I cannot move out 'vdata' as a global variable since each VM instances must have its own job queue.