*** empty log message ***
[csql.git] / test / dbapi / Connection / threadtest1.c
blob55f081b787e34498bad5f9b8453b9fd0ebb88481
1 #include <stdlib.h>
2 #include <pthread.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <CSql.h>
6 void* print_message_function (void *ptr);
7 int flag=0;
8 int main (int argc, char **argv)
10 Connection conn;
11 DbRetVal rv = conn.open("root","manager");
12 if (rv != 0) return 1;
13 pthread_t thread1, thread2;
14 char *message1 = "Thread 1";
15 char *message2 = "Thread 2";
16 long status1, status2;
17 pthread_create (&thread1, NULL,
18 &print_message_function, (void *) message1);
19 pthread_create (&thread2, NULL,
20 &print_message_function, (void *) message2);
22 pthread_join(thread1, (void **)&status1);
23 pthread_join(thread2, (void **)&status2);
25 DatabaseManager *dbMgr = conn.getDatabaseManager();
26 if (dbMgr == NULL) { printf("Auth failed \n"); conn.close(); return NULL; }
27 rv = dbMgr->dropTable("t1");
28 if ( rv != OK ) return 2;
29 rv = conn.close();
30 if (rv != 0) return 3;
32 if( 1 == (status1 + status2) ) return 0;
33 else return -1;
37 void* print_message_function(void *ptr)
39 //if (flag == 0) {flag =1; sleep(2); }
40 Connection conn;
41 DbRetVal rv=conn.open("root","manager");
42 if(rv!=OK)
44 printf("Thread Return value of open %d %d\n", rv, getpid());
45 return NULL;
47 DatabaseManager *dbMgr = conn.getDatabaseManager();
48 if (dbMgr == NULL) { printf("Auth failed\n"); conn.close(); return NULL;}
50 TableDef tabDef;
51 tabDef.addField("f1", typeInt);
52 tabDef.addField("f2", typeInt);
53 rv = dbMgr->createTable("t1", tabDef);
54 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return (void*) 1; }
55 printf("Table created %d %lu\n", os::getpid(), os::getthrid());
57 rv = conn.close();
58 if (rv != OK) { printf("Thread Return value of close %d %d\n", rv, getpid()); }
59 return NULL;