Ejemplo n.º 1
0
/****************************** MAIN THREAD'S CODE *********************************/
int main(int argc,char *argv[])
{
    int worker;
    pthread_t customerThreads[totalcustomers], postalWorkerThreads[totalPostalWorkers];
    int customerNo, postalWorkerNo;
	int custids[totalcustomers];
	int pwids[totalPostalWorkers];
    int errcode;
    int *status;

	//Initialise the semaphores
	initSemaphores();
	createQueues();


    // create the Customer threads
	for (customerNo=0; customerNo<totalcustomers; customerNo++) 
    {
		custids[customerNo]=customerNo;
        // create thread
        if (errcode = pthread_create(&customerThreads[customerNo],NULL,customer,&custids[customerNo]))
        {
            printf("Thread could not be created");
        }
	}
	
	// create the Postal Worker threads
    for (postalWorkerNo=0; postalWorkerNo<totalPostalWorkers; postalWorkerNo++) 
    {
		pwids[postalWorkerNo]=postalWorkerNo;
        // create thread
        if (errcode = pthread_create(&postalWorkerThreads[postalWorkerNo],NULL,postalWorker,&pwids[postalWorkerNo]))
        {
            printf("Thread could not be created");
        }
    }

	//join the customer threads as they exit
    for (customerNo=0; customerNo<totalcustomers; customerNo++)
    {
        if(errcode=pthread_join(customerThreads[customerNo],(void*)&status))
        {
           printf("Thread could not be joined");
        }
        
      //check thread's exit status, should be the same as the thread number for this example
        if (*status != customerNo) 
        {
			printf("Customer thread %d terminated abnormally\n\n",customerNo);
			exit(1);
        }
		else
		{
			printf("Customer %d joined\n",*status);
		}

    }
	
    return(0);
}
Ejemplo n.º 2
0
bool Context::init(QList<int> devIds, bool glInterop)
{
    // Select devices in the list (thread-safe)
    if(!devMgr().selectDevices(devIds))
        return false;
    // Create context
    if(!createContext(glInterop))
        return false;
    // Now we must create the device queues and pass them to the DeviceManager
    if(!createQueues())
        return false;
    _initialized= true;
    return true;
}
Ejemplo n.º 3
0
bool Context::init(cl_device_type devType, bool glInterop)
{
    // Select the devices of type devType (thread-safe)
    if(!devMgr().selectDevices(devType))
        return false;
    // Create context
    if(!createContext(glInterop))
        return false;
    // Now we must create the device queues and pass them to the DeviceManager
    if(!createQueues())
        return false;
    _initialized= true;
    return true;
}
Ejemplo n.º 4
0
int main(void) {
	srand(time(NULL));

	createQueues();

	setupThreads();

	createThreads(cpuThread, cpuThreads, NUMBER_OF_CPU_THREADS);
	createThreads(ioThread, ioThreads, NUMBER_OF_IO_THREADS);
	createThreads(submissionThread, submissionThreads, NUMBER_OF_SUBMISSION_THREADS);

	waitForThreads(cpuThreads);
	waitForThreads(ioThreads);
	waitForThreads(submissionThreads);

	printf("All threads complete.\n");

	return EXIT_SUCCESS;
}