OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-6.8/] [pre-binutils-2.20.1-sync/] [gdb/] [testsuite/] [gdb.threads/] [print-threads.c] - Diff between revs 157 and 223

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 157 Rev 223
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
#include <pthread.h>
#include <pthread.h>
 
 
void *thread_function(void *arg); /* Pointer to function executed by each thread */
void *thread_function(void *arg); /* Pointer to function executed by each thread */
 
 
int slow = 0;
int slow = 0;
 
 
#define NUM 5
#define NUM 5
 
 
int main() {
int main() {
    int res;
    int res;
    pthread_t threads[NUM];
    pthread_t threads[NUM];
    void *thread_result;
    void *thread_result;
    int args[NUM];
    int args[NUM];
    int i;
    int i;
 
 
    for (i = 0; i < NUM; i++)
    for (i = 0; i < NUM; i++)
      {
      {
        args[i] = i;
        args[i] = i;
        res = pthread_create(&threads[i], NULL, thread_function, (void *)&args[i]);
        res = pthread_create(&threads[i], NULL, thread_function, (void *)&args[i]);
      }
      }
 
 
    for (i = 0; i < NUM; i++)
    for (i = 0; i < NUM; i++)
      res = pthread_join(threads[i], &thread_result);
      res = pthread_join(threads[i], &thread_result);
 
 
    printf ("Done\n");
    printf ("Done\n");
 
 
    if (slow)
    if (slow)
      sleep (4);
      sleep (4);
 
 
    exit(EXIT_SUCCESS);
    exit(EXIT_SUCCESS);
}
}
 
 
void *thread_function(void *arg) {
void *thread_function(void *arg) {
    int my_number = *(int *)arg;
    int my_number = *(int *)arg;
    int rand_num;
    int rand_num;
 
 
    printf ("Print 1, thread %d\n", my_number);
    printf ("Print 1, thread %d\n", my_number);
    sleep (1);
    sleep (1);
 
 
    if (slow)
    if (slow)
      {
      {
        printf ("Print 2, thread %d\n", my_number);
        printf ("Print 2, thread %d\n", my_number);
        sleep (1);
        sleep (1);
        printf ("Print 3, thread %d\n", my_number);
        printf ("Print 3, thread %d\n", my_number);
        sleep (1);
        sleep (1);
        printf ("Print 4, thread %d\n", my_number);
        printf ("Print 4, thread %d\n", my_number);
        sleep (1);
        sleep (1);
        printf ("Print 5, thread %d\n", my_number);
        printf ("Print 5, thread %d\n", my_number);
        sleep (1);
        sleep (1);
      }
      }
 
 
    printf("Bye from %d\n", my_number);
    printf("Bye from %d\n", my_number);
    pthread_exit(NULL);
    pthread_exit(NULL);
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.