LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/thread - alloc.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 19 19
Test Date: 2026-03-03 17:14:48 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            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           32 : 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           32 :     char **r = NULL;
      36              :     EXEC SQL END DECLARE SECTION;
      37              : 
      38           32 :     value = (intptr_t) arg;
      39           32 :     sprintf(name, "Connection: %d", value);
      40              : 
      41           32 :     EXEC SQL CONNECT TO REGRESSDB1 AS :name;
      42           32 :     EXEC SQL SET AUTOCOMMIT TO ON;
      43         1632 :     for (i = 1; i <= REPEATS; ++i)
      44              :     {
      45         1600 :         EXEC SQL SELECT relname INTO :r FROM pg_class WHERE relname = 'pg_class';
      46         1600 :         free(r);
      47         1600 :         r = NULL;
      48              :     }
      49           32 :     EXEC SQL DISCONNECT :name;
      50           32 : 
      51           32 :     return 0;
      52              : }
      53              : 
      54            2 : 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              : #ifdef WIN32
      64              :     for (i = 0; i < THREADS; ++i)
      65              :     {
      66              :         unsigned id;
      67              :         threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
      68              :     }
      69              : 
      70              :     WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
      71              :     for (i = 0; i < THREADS; ++i)
      72              :         CloseHandle(threads[i]);
      73              : #else
      74           34 :     for (i = 0; i < THREADS; ++i)
      75           32 :         pthread_create(&threads[i], NULL, fn, (void *) i);
      76           34 :     for (i = 0; i < THREADS; ++i)
      77           32 :         pthread_join(threads[i], NULL);
      78              : #endif
      79              : 
      80            2 :     return 0;
      81              : }
        

Generated by: LCOV version 2.0-1