Exemplo n.º 1
0
Arquivo: pitest-5.c Projeto: 1587/ltp
int main(int argc, char **argv)
{
	pthread_mutexattr_t mutex_attr;
	pthread_attr_t threadattr;
	pthread_t threads[cpus - 1], threadsample, threadtp, threadtl, threadtb;
	time_t multiplier = 1;
	int i;
	int rc;

	test_set_priority(pthread_self(), SCHED_FIFO, 6);
	base_time = seconds_read();
	cpus = sysconf(_SC_NPROCESSORS_ONLN);

	/* Initialize a mutex with PTHREAD_PRIO_INHERIT protocol */
	mutex_attr_init(&mutex_attr);
	mutex_init(&mutex, &mutex_attr);

	/* Initialize thread attr */
	threadattr_init(&threadattr);

	/* Start the sample thread */
	DPRINTF(stderr, "Main Thread: Creating sample thread\n");
	rc = pthread_create(&threadsample, &threadattr, thread_sample, NULL);
	if (rc != 0) {
		EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc));
		exit(UNRESOLVED);
	}
	/* Start the TF threads */
	DPRINTF(stderr, "Main Thread: Creating %d TF threads\n", cpus - 1);
	for (i = 0; i < cpus - 1; i++) {
		rc = pthread_create(&threads[i], &threadattr, thread_fn,
				    &tp[i + 2]);
		if (rc != 0) {
			EPRINTF("UNRESOLVED: pthread_create: %d %s",
				rc, strerror(rc));
			exit(UNRESOLVED);
		}
	}

	sleep(base_time + multiplier * 10 - seconds_read());

	/* Start TP thread */
	DPRINTF(stderr, "Main Thread: Creating TP thread\n");
	rc = pthread_create(&threadtp, &threadattr, thread_fn, &tp[1]);
	if (rc != 0) {
		EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc));
		exit(UNRESOLVED);
	}
	sleep(base_time + multiplier * 20 - seconds_read());

	/* Start TL thread */
	DPRINTF(stderr, "Main Thread: Creating TL thread\n");
	rc = pthread_create(&threadtl, &threadattr, thread_tl, &tp[0]);
	if (rc != 0) {
		EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc));
		exit(UNRESOLVED);
	}
	sleep(base_time + multiplier * 30 - seconds_read());

	/* Start TB thread (boosting thread) */
	rc = pthread_create(&threadtb, &threadattr, thread_tb, NULL);
	if (rc != 0) {
		EPRINTF("UNRESOLVED: pthread_create: %d %s", rc, strerror(rc));
		exit(UNRESOLVED);
	}
	sleep(base_time + multiplier * 40 - seconds_read());
	unlock_mutex = 1;
	sleep(base_time + multiplier * 50 - seconds_read());

	/* Stop TL thread */
	tp[0].stop = 1;
	sleep(base_time + multiplier * 60 - seconds_read());

	/* Stop TP thread */
	tp[1].stop = 1;
	sleep(base_time + multiplier * 70 - seconds_read());

	/* Stop TF threads */
	for (i = 2; i < cpus - 1; i++) {
		tp[i].stop = 1;
	}

	/* Stop sampler */
	ts_stop = 1;
	DPRINTF(stderr, "Main Thread: stop sampler thread\n");
	return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	pthread_mutexattr_t mutex_attr;
	pthread_attr_t	threadattr;
	pthread_t *threads, threadsample, threadtp, threadtl, threadtb;
	
	int multiplier = 1;
	int i;
	int rc;

	test_set_priority(pthread_self(), SCHED_FIFO, 6);
	cpus = sysconf(_SC_NPROCESSORS_ONLN);

	threads = malloc((cpus - 1) * sizeof(pthread_t));
	if (threads == NULL)
		return -ENOMEM;

        tp = malloc((cpus + 1) * sizeof(struct thread_param));
        if (tp == NULL) {
		free(threads);
                return -ENOMEM;
	} else {
	        set_thread_param(0, 0, 0, 0, 1, SCHED_FIFO, "TL", 0, 0, 0, 0);
        	set_thread_param(1, 1, 0, 50, 2, SCHED_FIFO, "TP", 0, 0, 0, 0);
        	for(i = 1; i <= cpus-1; i++)
                	set_thread_param(i + 1, i + 1, 0, 0, 3, SCHED_FIFO, "TF", i, 0, 0, 0);
	}
	

	base_time = seconds_read(); 
	
	/* Initialize a mutex with PTHREAD_PRIO_INHERIT protocol */
	mutex_attr_init(&mutex_attr);
	mutex_init(&mutex, &mutex_attr);

	/* Initialize thread attr */
	threadattr_init(&threadattr);
	
	/* Start the sample thread */
	DPRINTF(stderr,"Main Thread: start sample thread \n");
	rc = pthread_create(&threadsample, &threadattr, thread_sample, NULL);
        if (rc != 0) {
                EPRINTF("UNRESOLVED: pthread_create: %d %s",
                        rc, strerror(rc));
                exit(UNRESOLVED);
        }
	
	/* Start the TF threads */
	DPRINTF(stderr,"Main Thread: start %d TF thread\n", cpus-1);
	for (i = 0; i < cpus - 1; i++) 
	{
		rc = pthread_create(&threads[i], &threadattr, thread_fn, 
				    &tp[i + 2]);
	        if (rc != 0) {
	                EPRINTF("UNRESOLVED: pthread_create: %d %s",
	                        rc, strerror(rc));
	                exit(UNRESOLVED);
	        }
	}
	sleep(base_time + multiplier * 10 - seconds_read());

	/* Start TP thread */
		
	DPRINTF(stderr,"Main Thread: start TP thread\n");
	rc = pthread_create(&threadtp, &threadattr, thread_fn, &tp[1]);
        if (rc != 0) {
                EPRINTF("UNRESOLVED: pthread_create: %d %s",
                        rc, strerror(rc));
                exit(UNRESOLVED);
        }
	sleep(base_time + multiplier * 20 - seconds_read());

	/* Start TL thread */
	DPRINTF(stderr,"Main Thread: start TL thread\n");
	rc = pthread_create(&threadtl, &threadattr, thread_tl, &tp[0]);
        if (rc != 0) {
                EPRINTF("UNRESOLVED: pthread_create: %d %s",
                        rc, strerror(rc));
                exit(UNRESOLVED);
        }
	sleep(base_time + multiplier * 30 - seconds_read());

	/* Start TB thread (boosting thread) */
	DPRINTF(stderr,"Main Thread: start TB thread\n");
	int timeout = multiplier * 20;
	rc = pthread_create(&threadtb, &threadattr, thread_tb, 
			    &timeout);
        if (rc != 0) {
                EPRINTF("UNRESOLVED: pthread_create: %d %s",
                        rc, strerror(rc));
                exit(UNRESOLVED);
        }
	sleep(base_time + multiplier * 60 - seconds_read());

	/* Stop TL thread */
	
	DPRINTF(stderr,"Main Thread: stop TL thread\n");
	tp[0].stop = 1;
	sleep(base_time + multiplier * 70 - seconds_read());

	/* Stop TP thread */
	DPRINTF(stderr,"Main Thread: stop TP thread\n");
	tp[1].stop = 1;
	sleep(base_time + multiplier * 80 - seconds_read());

	/* Stop TF threads */
	DPRINTF(stderr,"Main Thread: stop TF threads\n");
	for (i = 2; i < cpus - 1; i++)
	{
		tp[i].stop = 1;
	}

	/* Stop sampler */
	ts_stop = 1;
	DPRINTF(stderr,"Main Thread: stop sampler thread \n");
	free(tp);
	free(threads);
	return 0;
}