Exemple #1
0
/*
 * The main program to "drive" the crew...
 */
int main (int argc, char *argv[])
{
    crew_t my_crew;
    char line[128], *next;
    int status;

    if (argc < 3) {
        fprintf (stderr, "Usage: %s string path\n", argv[0]);
        return -1;
    }

#ifdef sun
    /*
     * On Solaris 2.5, threads are not timesliced. To ensure
     * that our threads can run concurrently, we need to
     * increase the concurrency level to CREW_SIZE.
     */
    DPRINTF (("Setting concurrency level to %d\n", CREW_SIZE));
    thr_setconcurrency (CREW_SIZE);
#endif
    status = crew_create (&my_crew, CREW_SIZE);
    if (status != 0)
        err_abort (status, "Create crew");

    status = crew_start (&my_crew, argv[2], argv[1]);
    if (status != 0)
        err_abort (status, "Start crew");

    return 0;
}
Exemple #2
0
int main(int argc, char *argv[]){
	crew_t point;
	char line[128],*next;
	if(argc<3){
		fprintf(stderr,"Usage:%s string path\n",argv[0]);
		return -1;
	}
	int status=init_worker_crew(&point,work_crew_size);
//	assert(status==0);
	crew_start(&point,argv[2],argv[1]);
	return 0;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    if(argc<3)
        exit(-1);
    crew_t crew;
    if(crew_create(&crew,3)!=0){
        printf("crew create error\n");
        exit(-1);
    }
    crew_start(&crew,argv[2],argv[1]);

    return 0;
}
int openthreadsWorkCrew (int argc, char *argv []) {

    std::vector<WorkerThread *> workers;

    if(argc != 2) {
        std::cout << "Usage: workCrew [NUM_THREADS] " << std::endl;
        return 0;
    };

    const int NUM_THREADS = atoi(argv[1]);

    DPRINTF(("ROOT PID = %d\n", getpid()));

    Crew *crew = new Crew;

    crew->crewSize = NUM_THREADS;
    crew->workCount = 0;
    crew->first = 0;
    crew->last  = 0;
    
    float result = 0;
    unsigned int status = crew_create(crew, result, workers);
    assert(status == 0);

    status = crew_start(crew);
    assert(status == 0);

    printf("FINAL RESULT: %f\n", result);

    for(status = 0; status < workers.size(); ++status) {

	WorkerThread *thread = workers[status];
	delete thread;

    }
    workers.clear();

    delete crew;
    return EXIT_SUCCESS;
}
Exemple #5
0
int main (int argc, char **argv) {

    std::vector<WorkerThread *> workers;

    if(argc != 2) {
        std::cout << "Usage: workCrew [NUM_THREADS] " << std::endl;
        return 0;
    };

    const int NUM_THREADS = atoi(argv[1]);

#ifndef _WIN32
	DPRINTF(("ROOT PID = %d\n", getpid()));
#endif

    Crew *crew = new Crew;

    crew->crewSize = NUM_THREADS;
    crew->workCount = 0;
    crew->first = 0;
    crew->last  = 0;
    
    float result = 0;
    unsigned int status = crew_create(crew, result, workers);
    assert(status == 0);

    status = crew_start(crew);
    assert(status == 0);

	std::list<WorkerThread *> late_workers;
	for (std::vector<WorkerThread *>::iterator it = workers.begin(); it != workers.end(); ++it)
		if ((*it)->isRunning()) { late_workers.push_back(*it); (*it)->cancel(); }
			
#ifdef _WIN32
	// On Windows, with more than 2 threads, this program hangs if we join the threads
	// And it crashes/deadlocks if we don't properly end the threads.
	DWORD wait_start_tick = GetTickCount();
	while (!late_workers.empty() && (GetTickCount() - wait_start_tick) < 1000) {

		OpenThreads::Thread::microSleep(100000);
		for (auto it = late_workers.begin(); it != late_workers.end();)
			if (!(*it)->isRunning())
				it = late_workers.erase(it);
			else
				++it;
	}
	for (auto it = late_workers.begin(); it != late_workers.end(); ++it) {
		printf("Thread %d deadlocked? Killing it.\n", (*it)->getThreadId());
		(*it)->setCancelModeAsynchronous();
		(*it)->cancel();
	}
	
#endif //_WIN32

	printf("FINAL RESULT: %f\n", result);

    for(status = 0; status < workers.size(); ++status) {

		WorkerThread *thread = workers[status];
		thread->join();
		delete thread;

    }
    workers.clear();

    delete crew;
}