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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1235 - (show annotations) (download) (as text)
Fri Dec 4 11:35:24 2009 UTC (12 years, 9 months ago) by aramv
File MIME type: text/x-chdr
File size: 1705 byte(s)
Moved around control logic of the parser to stop and report errors if they are encountered
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <pthread.h>
4 #include "config.h"
5 #include "eef.h"
6 #include "aos.h"
7
8 #define NUM_THREADS 4
9
10 void *threaded_aos_setting(void* foo);
11 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 void *threaded_aos_setting(void* tid){
27 char* label = label_from_tid((long) tid);
28 printf("Setting %s in thread %li\n", label, (long) tid);
29 setObligation(label, "foobar");
30 return NULL;
31 }
32
33 void *threaded_aos_getting(void* tid){
34 char* label = label_from_tid((long) tid);
35 printf("Getting in thread %li\n", (long) tid);
36 printf("Got: %s\n", getObligation(label));
37 return NULL;
38 }
39
40 int main (int argc, char* argv[]){
41 char* config_file;
42 pthread_t threads[NUM_THREADS];
43 long t;
44 int rc;
45
46 if(argc > 1){
47 config_file = argv[1];
48 } else {
49 config_file = "examples/example_1.pdl";
50 }
51
52 printf("Parsing config file %s\n", config_file);
53
54 if(EEF_Init(config_file, NULL, 0, NULL) == EES_FAILURE){
55 eef_log(LOG_ERR, "Failed to parse config file (%s), exiting...", config_file);
56 } else {
57 /* start threading */
58 for(t=0; t < NUM_THREADS; t+=2){
59 printf("Creating thread %li!\n", t);
60 rc = pthread_create(&threads[t], NULL, threaded_aos_setting, (void*)t);
61 rc = pthread_create(&threads[t+1], NULL, threaded_aos_getting, (void*)t);
62 }
63 pthread_exit(NULL);
64 }
65 EEF_Term();
66 return 0;
67 }
68

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