Line data Source code
1 : #include <stdint.h> 2 : #include <stdlib.h> 3 : #include "ecpg_config.h" 4 : 5 : #ifdef WIN32 6 : #define WIN32_LEAN_AND_MEAN 7 : #include <windows.h> 8 : #include <process.h> 9 : #include <locale.h> 10 : #else 11 : #include <pthread.h> 12 : #endif 13 : #include <stdio.h> 14 : 15 : #define THREADS 16 16 : #define REPEATS 50 17 : 18 : exec sql include sqlca; 19 : exec sql include ../regression; 20 : 21 : exec sql whenever sqlerror sqlprint; 22 : exec sql whenever not found sqlprint; 23 : 24 : #ifdef WIN32 25 : static unsigned __stdcall fn(void* arg) 26 : #else 27 64 : static void* fn(void* arg) 28 : #endif 29 : { 30 : int i; 31 : 32 : EXEC SQL BEGIN DECLARE SECTION; 33 : int value; 34 : char name[100]; 35 64 : char query[256] = "INSERT INTO T VALUES ( ? )"; 36 : EXEC SQL END DECLARE SECTION; 37 : 38 64 : value = (intptr_t) arg; 39 64 : sprintf(name, "Connection: %d", value); 40 : 41 64 : EXEC SQL CONNECT TO REGRESSDB1 AS :name; 42 64 : EXEC SQL SET AUTOCOMMIT TO ON; 43 3264 : for (i = 1; i <= REPEATS; ++i) 44 : { 45 3200 : EXEC SQL PREPARE I FROM :query; 46 3200 : EXEC SQL EXECUTE I USING :value; 47 3200 : } 48 64 : EXEC SQL DEALLOCATE I; 49 64 : EXEC SQL DISCONNECT :name; 50 64 : 51 64 : return 0; 52 : } 53 : 54 4 : int main () 55 : { 56 : intptr_t i; 57 : #ifdef WIN32 58 : HANDLE threads[THREADS]; 59 : #else 60 : pthread_t threads[THREADS]; 61 : #endif 62 : 63 4 : EXEC SQL CONNECT TO REGRESSDB1; 64 4 : EXEC SQL SET AUTOCOMMIT TO ON; 65 4 : EXEC SQL DROP TABLE IF EXISTS T; 66 4 : EXEC SQL CREATE TABLE T ( i int ); 67 4 : EXEC SQL DISCONNECT; 68 4 : 69 : #ifdef WIN32 70 : for (i = 0; i < THREADS; ++i) 71 : { 72 : unsigned id; 73 : threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id); 74 : } 75 : 76 : WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE); 77 : for (i = 0; i < THREADS; ++i) 78 : CloseHandle(threads[i]); 79 : #else 80 68 : for (i = 0; i < THREADS; ++i) 81 64 : pthread_create(&threads[i], NULL, fn, (void *) i); 82 68 : for (i = 0; i < THREADS; ++i) 83 64 : pthread_join(threads[i], NULL); 84 : #endif 85 : 86 4 : return 0; 87 : }