int main(int argc, char** argv) {
  args(argc, argv);
  pthread_t* handles = new pthread_t[nStealers];
	ObjType* items = new ObjType[nItems];

	WorkStealQueue<ObjType*> *q = new WorkStealQueue<ObjType*>(INITQSIZE);

	for (int i = 0; i < nStealers; i++) {
		pthread_create(&handles[i], NULL, Stealer, (void*)q);
	}

	
	for (int i = 0; i < nItems/2; i++) {
		q->Push(&items[2*i]);
		q->Push(&items[2*i+1]);

		ObjType* r; 
		if (q->Pop(r)) 
			r->Operation(); 
	}

	for (int i = 0; i < nItems/2; i++) {
		ObjType* r; 
		if (q->Pop(r)) 
			r->Operation(); 
	}


	for (int i = 0; i < nStealers; i++) {
    pthread_join(handles[i], NULL);
  }

	for (int i = 0; i < nItems; i++) {
		items[i].Check();
	}

	delete[] items;
	delete[] handles;
	delete q;
	return 0;
}
예제 #2
0
__declspec(dllexport) int ChessTestRun(){
	HANDLE*  handles = new HANDLE[nStealers];
	ObjType* items = new ObjType[nItems];

	WorkStealQueue<ObjType*> *q = new WorkStealQueue<ObjType*>(INITQSIZE);

	for (int i = 0; i < nStealers; i++) {
		DWORD tid;
		handles[i] = CreateThread(NULL, 0, Stealer, q, 0, &tid);
	}

	
	for (int i = 0; i < nItems/2; i++) {
		q->Push(&items[2*i]);
		q->Push(&items[2*i+1]);

		ObjType* r; 
		if (q->Pop(r)) 
			r->Operation(); 
	}

	for (int i = 0; i < nItems/2; i++) {
		ObjType* r; 
		if (q->Pop(r)) 
			r->Operation(); 
	}


	WaitForMultipleObjects(nStealers, handles, TRUE, INFINITE);

	for (int i = 0; i < nItems; i++) {
		//items[i].Check();
	}

	delete[] items;
	delete[] handles;
	delete q;
	return 0;
}