00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <unistd.h>
00034
00035 #include "erregapi.h"
00036
00037 #include "erregxsd.h"
00038 #include "erregxml.h"
00039 #include "erregtypes_f.h"
00040 #include "erreglog.h"
00041
00042 static void testThreads(void);
00043
00044
00045 int main()
00046 {
00047 gboolean bRet;
00048
00049
00050 bRet = erRegRWLockInit();
00051 if (FALSE == bRet)
00052 {
00053 ERREG_ERRORPRINTF("error");
00054 return 0;
00055 }
00056
00057 testThreads();
00058
00059
00060 erRegRWLockDestroy();
00061
00062 return 0;
00063 }
00064
00065 #include <pthread.h>
00066 #define MAX_ARGC 20
00067 static pthread_t tid[MAX_ARGC];
00068 static const char *Okay = "OK";
00069 static const char *Failed = "Failed";
00070
00071 static void *threadFunc(void *private_data)
00072 {
00073 int okay = 1;
00074 gboolean bRet;
00075
00076
00077
00078 bRet = erRegReadLock();
00079 if (FALSE == bRet)
00080 {
00081 ERREG_ERRORPRINTF("error");
00082 return FALSE;
00083 }
00084
00085 while (1)
00086 {
00087 ERREG_ERRORPRINTF("HERE");
00088 usleep(5*1000);
00089 }
00090
00091
00092 erRegUnlock();
00093
00094 if (okay == 0)
00095 return((void *) Failed);
00096 return ((void *) Okay);
00097 }
00098
00099 static void testThreads(void)
00100 {
00101 unsigned int i;
00102 unsigned int num_threads = 4;
00103 void *results[MAX_ARGC];
00104 int ret;
00105
00106 for (i = 0; i < num_threads; i++) {
00107 results[i] = NULL;
00108 tid[i] = (pthread_t) -1;
00109 }
00110
00111 for (i = 0; i < num_threads; i++) {
00112 ret = pthread_create(&tid[i], NULL, threadFunc,
00113 (void *) NULL);
00114 if (ret != 0) {
00115 ERREG_ERRORPRINTF("pthread_create");
00116 perror("pthread_create");
00117 exit(1);
00118 }
00119 }
00120 for (i = 0; i < num_threads; i++) {
00121 ret = pthread_join(tid[i], &results[i]);
00122 if (ret != 0) {
00123 ERREG_ERRORPRINTF("pthread_join");
00124 perror("pthread_join");
00125 exit(1);
00126 }
00127 }
00128
00129 for (i = 0; i < num_threads; i++)
00130 if (results[i] != (void *) Okay)
00131 ERREG_ERRORPRINTF("Thread %d handling failed", i);
00132 }
00133
00134
00135
00136
00137