/[pdpsoft]/trunk/grid-mw-security/ees/src/app/aos_threading_test.c
ViewVC logotype

Diff of /trunk/grid-mw-security/ees/src/app/aos_threading_test.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1230 by aramv, Thu Dec 3 15:22:32 2009 UTC revision 1231 by aramv, Thu Dec 3 16:34:10 2009 UTC
# Line 1  Line 1 
1  #include <stdio.h>  #include <stdio.h>
2    #include <stdlib.h>
3  #include <pthread.h>  #include <pthread.h>
4  #include "config.h"  #include "config.h"
5  #include "eef.h"  #include "eef.h"
# Line 6  Line 7 
7    
8  #define NUM_THREADS 2  #define NUM_THREADS 2
9    
10  int threaded_aos_setting(long foo);  void *threaded_aos_setting(void* foo);
11  int threaded_aos_getting(long foo);  void *threaded_aos_getting(void* foo);
12    char* label_from_tid(long tid);
13    
14    char* label_from_tid(long tid){
15      char* label = NULL;
16      char tid_string[2] ;
17      char* label_prefix = "label_";
18      sprintf(tid_string, "%li", tid);
19      if((label = malloc((sizeof(char) * (strlen(label_prefix) + strlen(tid_string) + 1))))){
20        strcat(label, label_prefix);
21        strcat(label, tid_string);
22      }
23      return label;
24    }
25    
26  int threaded_aos_setting(long foo){  void *threaded_aos_setting(void* tid){
27    setObligation(foo, "foobar");    char* label = label_from_tid((long) tid);
28    printf("Setting in thread %li\n", foo);    printf("Setting %s in thread %li\n", label, (long) tid);
29    return 1;    setObligation(label, "foobar");
30      return NULL;
31  }  }
32    
33  int threaded_aos_getting(long foo){  void *threaded_aos_getting(void* tid){
34    printf("Getting in thread %i\n", foo);    char* label = label_from_tid((long) tid);
35    /*printf("Got: %p\n", getObligation("foobar"));*/    printf("Getting in thread %li\n", (long) tid);
36    return 1;    printf("Got: %s\n", getObligation(label));
37      return NULL;
38  }  }
39    
40  int main (int argc, char* argv[]){  int main (int argc, char* argv[]){
# Line 40  int main (int argc, char* argv[]){ Line 56  int main (int argc, char* argv[]){
56    } else {    } else {
57      /* start threading */      /* start threading */
58      for(t=0; t < NUM_THREADS; t++){      for(t=0; t < NUM_THREADS; t++){
59          printf("Creating thread %li!\n", t);
60        rc = pthread_create(&threads[t], NULL, threaded_aos_setting, (void*)t);        rc = pthread_create(&threads[t], NULL, threaded_aos_setting, (void*)t);
61        rc = pthread_create(&threads[t], NULL, threaded_aos_getting, (void*)t);        rc = pthread_create(&threads[t], NULL, threaded_aos_getting, (void*)t);
62      }      }
63        pthread_exit(NULL);
64    }    }
65    EEF_Term();    EEF_Term();
66    return 0;    return 0;

Legend:
Removed from v.1230  
changed lines
  Added in v.1231

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28