42{
43#ifndef WIN32
44 pthread_t *threads;
45#else
46 HANDLE *threads;
47#endif
48 intptr_t n;
49 /* exec sql begin declare section */
50
51
52#line 32 "thread.pgc"
53 int l_rows ;
54/* exec sql end declare section */
55#line 33 "thread.pgc"
56
57
58 /* Do not switch on debug output for regression tests. The threads get executed in
59 * more or less random order */
60 /* ECPGdebug(1, stderr); */
61
62 /* setup test_thread table */
63 {
ECPGconnect(__LINE__, 0,
"ecpg1_regression" , NULL, NULL , NULL, 0); }
64#line 40 "thread.pgc"
65
67#line 41 "thread.pgc"
68 /* DROP might fail */
70#line 42 "thread.pgc"
71
72 {
ECPGdo(__LINE__, 0, 1, NULL, 0,
ECPGst_normal,
"create table test_thread ( tstamp timestamp not null default cast ( timeofday ( ) as timestamp ) , thread text not null , iteration integer not null , primary key ( thread , iteration ) )",
ECPGt_EOIT,
ECPGt_EORT);}
73#line 47 "thread.pgc"
74
76#line 48 "thread.pgc"
77
79#line 49 "thread.pgc"
80
81
82 /* create, and start, threads */
84 if( threads == NULL )
85 {
86 fprintf(stderr,
"Cannot alloc memory\n");
87 return 1;
88 }
90 {
91#ifndef WIN32
92 pthread_create(&threads[n], NULL,
test_thread, (
void *) (n + 1));
93#else
94 threads[n] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) (
void (*) (
void))
test_thread, (
void *) (n + 1), 0, NULL);
95#endif
96 }
97
98 /* wait for thread completion */
99#ifndef WIN32
101 {
102 pthread_join(threads[n], NULL);
103 }
104#else
105 WaitForMultipleObjects(
nthreads, threads, TRUE, INFINITE);
106#endif
108
109 /* and check results */
110 {
ECPGconnect(__LINE__, 0,
"ecpg1_regression" , NULL, NULL , NULL, 0); }
111#line 79 "thread.pgc"
112
114 ECPGt_int,&(l_rows),(
long)1,(
long)1,
sizeof(
int),
116#line 80 "thread.pgc"
117
119#line 81 "thread.pgc"
120
122#line 82 "thread.pgc"
123
126 else
128
129 return 0;
130}
bool ECPGdisconnect(int lineno, const char *connection_name)
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
#define fprintf(file, fmt, msg)
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
void * test_thread(void *arg)