示例#1
0
int
main ()
{
    int res;
    pthread_t threads[NUM];
    void *thread_result;
    long i;

    /* To keep the test determinative, initialize args first,
       then start all the threads.  Otherwise, the way watchthreads.exp
       is written, we have to worry about things like threads[0] getting
       to 29 hits of args[0] before args[1] gets changed.  */

    for (i = 0; i < NUM; i++)
      {
	/* The call to usleep is so that when the watchpoint triggers,
	   the pc is still on the same line.  */
	args[i] = 1; usleep (1); /* Init value.  */
      }

    for (i = 0; i < NUM; i++)
      {
	res = pthread_create (&threads[i],
			      NULL,
			      thread_function,
			      (void *) i);
      }

    args[i] = 1;
    thread_function ((void *) i);

    exit (EXIT_SUCCESS);
}
int main( int argc, char **argv )
{
   long i, j;
   pthread_t ids[NUM_THREADS-1];
   struct timeval start, end;
   double d;

   if (argc > 1) {
       NUM_THREADS = atoi(argv[1]);
   }
   printf("NUM_THREAD = %d NUM_ITERATIONS = %lu\n", NUM_THREADS, NUM_ITERATIONS);

   //data = (uint32_t*)malloc( sizeof(uint32_t)*NUM_THREADS );
   data = (uint32_t*)malloc( sizeof(uint32_t)*64 );

   if (!data) {
       perror("malloc");
       return 1;
   }

   for ( j = 1; j <= NUM_THREADS; j++ )
   {
       for ( i = 0; i < NUM_THREADS; i++ )
       {
           data[i] = 0;
       }

       gettimeofday( &start, NULL );
       for ( i = 0; i < j-1; i++ )
       {
           pthread_create( ids+i, NULL, thread_function, (void*)i );
       }

       thread_function( (void*)i );

       for ( i = 0; i < j-1; i++ )
       {
           pthread_join( ids[i], NULL );
       }

       gettimeofday( &end, NULL );

       d = end.tv_sec - start.tv_sec + (1.0e-6)*end.tv_usec - (1.0e-6)*start.tv_usec;

       printf( "%ld) %g %g ips\n", j, d, ((double)j*NUM_ITERATIONS)/d );
   }

   return 0;
}
示例#3
0
int main() {
    int res;
    pthread_t threads[NUM];
    void *thread_result;
    int i;

    for (i = 0; i < NUM; i++)
    {
        args[i] = 1;
        res = pthread_create(&threads[i], NULL, thread_function, (void *)i);
    }

    /* schedlock.exp: last thread start.  */
    args[i] = 1;
    thread_function ((void *) i);

    exit(EXIT_SUCCESS);
}
int main () {
    int res;
    pthread_t threads[NUM];
    void *thread_result;
    long i;

    for (i = 0; i < NUM; i++)
      {
        res = pthread_create (&threads[i],
                             NULL,
                             thread_function,
			     (void *) i);
      }

    thread_result = thread_function ((void *) i);

    exit (EXIT_SUCCESS);
}
int main() {
    int res;
    pthread_t threads[NUM];
    void *thread_result;
    long i;

    for (i = 0; i < NUM; i++)
      {
	args[i] = 1; /* Init value.  */
	res = pthread_create(&threads[i],
		             NULL,
			     thread_function,
			     (void *) i);
      }

    args[i] = 1;
    thread_function ((void *) i);

    exit(EXIT_SUCCESS);
}
示例#6
0
文件: mfind.c 项目: angmori/mfind_p
int main(int argc, char* argv[])
{
    char type = 'a';
    int nrthr = get_options(argc, argv, &type);
    pthread_t threads[nrthr];
    extern int optind;
    extern char *optarg;

    struct listnode *first_node = NULL;
    struct search_args *args = malloc(sizeof(struct search_args));

    args->active_threads = nrthr;
    args->phrase = argv[argc - 1];
    args->type = &type;
    args->first_node_ptr = &first_node;

    chdir("/home");

    //Add all the paths to the list of search paths.
    for (int i = optind; i <= argc - 2; i++) {
        struct listnode *tmp_node = create_node(argv[i]);
        insert_node(&first_node, tmp_node);
    }

    //Create threads.
    for (int i = 0; i < nrthr - 1; i++) {
        pthread_create(&threads[i], NULL, thread_function, (void *)args);
    }

    //Main thread work.
    thread_function((void *)args);

    //Join threads.
    for (int i = 0; i < nrthr - 1; i++) {
        pthread_join(threads[i], NULL);
    }

    free(args);

    return 0;
}
示例#7
0
int main()
{
	int i;
        int thread_id;
	int thread_id_array[NUM_TH];

        pthread_barrier_init(&barr, NULL, NUM_TH);
        //Start threads
        for(thread_id=0; thread_id < NUM_TH - 1; thread_id++)
        {
		thread_id_array[thread_id] = thread_id;
                pthread_create( &thread[thread_id], NULL, thread_function, (void*) (thread_id_array + thread_id) );
        }
	thread_id_array[thread_id] = thread_id;
        thread_function((void*) (thread_id_array + thread_id));

//#ifdef DUMP
//	m5_dump_stats(0, 0);
//	m5_reset_stats(0, 0);
//#endif

	return 0;
}
示例#8
0
int main() {
    int res;
    int all_started;
    pthread_t threads[NUM];
    void *thread_result;
    long i;

    for (i = 0; i < NUM; i++)
      {
	args[i] = 1; /* Init value.  */
	res = pthread_create(&threads[i],
		             NULL,
			     thread_function,
			     (void *) i);
      }

    all_started = 0;
    while (!all_started)
      {
	all_started = 1;
        for (i = 0; i < NUM; i++)
          {
            if (args[i] == 1)
	      {
	        all_started = 0;
	        break;
	      }
          }  
      }
	
    args[i] = 1;
    /* Break here */
    thread_function ((void *) i);

    exit(EXIT_SUCCESS);
}
示例#9
0
int main(int argc, char *argv[])
{
	prepare_input(argc, argv);
	string header;
/*
	if(argc == 2)
	{
		SEED = 40;
		//MAXREAD = 100;
		MAXTHREAD = (int) atol(argv[1]);
	}
	if(argc == 3)
	{
		SEED = 40;
		MAXREAD = (int) atol(argv[1]);
		MAXTHREAD = (int) atol(argv[2]);
		//cout << "Given MAX number of READ = " << MAXREAD << endl;
	}
	if(argc == 4)
	{
		SEED = (int) atol(argv[1]);
		MAXREAD = (int) atol(argv[2]);
		MAXTHREAD = (int) atol(argv[3]);
	}
*/
	cout << "KMER = " << KMER << ", SEED = " << SEED << ", MAXREAD = " << MAXREAD << endl;
	fp_meta.open(meta_file.c_str(), ifstream::in);
	getline(fp_meta, header);
	//cout << header << endl;

	/*
	ostringstream logstr;
	string log = "detail_alignment-";
	logstr << SEED << "-" << MINREAD << "-" << MAXREAD;
	log = log + logstr.str() + ".txt";
	FILE* freop = freopen(log.c_str(), "w", stdout);
	*/

	/*
	//thread_function();//single thread
	thread thread_test(thread_function);	
	thread_test.join();
	*/
	/*
	std::thread thread_object[MAXTHREAD];

        //Launch a group of threads
        for (int i = 0; i < MAXTHREAD; ++i) 
	{
                thread_object[i] = std::thread(thread_function, i);
        }

        std::cout << "Launched from the main\n";

        //Join the threads with the main thread
        for (int i = 0; i < MAXTHREAD; ++i) {
                thread_object[i].join();
        }
	*/

	int x, y, z, novalue;
	FILE* fstream1 = fopen("matching_score.txt", "r");
	for(int i = 0; i < 51; i++)
	{
		for(int k = 0; k < 51; k++)
		{
			novalue = fscanf(fstream1, "%d,%d,%d", &x, &y, &z);
			//cout << "x = " << x << ", y = " << y << ", z = " << z << endl;
			matching_score[x][y] = z;
		}
	}
	fclose(fstream1);

	FILE* fstream2 = fopen("mismatch_score.txt", "r");
	for(int i = 0; i < 51; i++)
	{
		for(int k = 0; k < 51; k++)
		{
			novalue = fscanf(fstream2, "%d,%d,%d", &x, &y, &z);
			//cout << "x = " << x << ", y = " << y << ", z = " << z << endl;
			mismatch_score[x][y] = z;
		}
	}
	fclose(fstream2);

	//return 0;

	thread_function(0);

	//fp_blastn.close();
	fp_meta.close();
	return 0;
}
/* fork the process, set up 2 pipes to the new process */
struct test_thread create_test_thread(int(*thread_function)(struct test_thread pipes, void* data), void* data){
	struct test_thread thread = {.read_descriptor = 0, .write_descriptor = 0};
	int write_to_thread_fd[2];
	int read_from_thread_fd[2];
	pid_t cpid;

	if(thread_function == NULL){
		perror("no thread function specified");
		exit(EXIT_FAILURE);
	}

	if(pipe(write_to_thread_fd) == -1){
		perror("pipe");
		exit(EXIT_FAILURE);
	}

	if(pipe(read_from_thread_fd) == -1){
		perror("pipe");
		exit(EXIT_FAILURE);
	}
	
	cpid = fork();

	if(cpid == -1) {
		perror("fork");
		exit(EXIT_FAILURE);
	}

	if(cpid == 0){ /* child process */
		int result;
		close(write_to_thread_fd[1]); /* close write end */
		close(read_from_thread_fd[0]); /* close read end */
		thread.read_descriptor = write_to_thread_fd[0];
		thread.write_descriptor = read_from_thread_fd[1];
		result = thread_function( thread, data);
		close(write_to_thread_fd[0]);
		close(read_from_thread_fd[1]);
		exit(result);
	} else {
		close(write_to_thread_fd[0]); /* close read end */
		close(read_from_thread_fd[1]); /* close write end */
		thread.read_descriptor = read_from_thread_fd[0];
		thread.write_descriptor = write_to_thread_fd[1];
		return thread;
	}
}

int echo_thread(struct test_thread pipes, void* data){
	char buffer[1];
	int bytes_red;
	int* dummy = (int*) data;
	dummy++;
	buffer[0] = 'b';
	bytes_red = read(pipes.read_descriptor, buffer, 1);
	if(bytes_red <= 0)
		exit(1);

	ck_assert_msg(*buffer == 'a', "thread not reading from parent");
	write(pipes.write_descriptor, buffer, 1);
	close(pipes.read_descriptor);
	close(pipes.write_descriptor);
	return 0;
}