1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-08 07:21:33 +03:00
Tom Lane e3565fd61c Remove _configthreadlocale() calls in ecpg test suite.
This essentially reverts commits a772624b1 and 04fbe0e45, which
added "_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)" calls to the
thread-related ecpg test programs.  That was nothing but a hack,
because we shouldn't expect that ecpg-using applications have
done that for us; and now that we've inserted such calls into
ecpglib, the tests should still pass without it.

(If they don't, it would be good to know that.)

HEAD only; there seems no big need to change this in the
back branches.

Discussion: https://postgr.es/m/22937.1548307384@sss.pgh.pa.us
2019-01-24 17:02:09 -05:00

90 lines
1.5 KiB
Plaintext

#include <stdlib.h>
#include "ecpg_config.h"
#ifndef ENABLE_THREAD_SAFETY
int
main(void)
{
printf("No threading enabled.\n");
return 0;
}
#else
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#include <locale.h>
#else
#include <pthread.h>
#endif
#include <stdio.h>
#define THREADS 16
#define REPEATS 50
exec sql include sqlca;
exec sql include ../regression;
exec sql whenever sqlerror sqlprint;
exec sql whenever not found sqlprint;
#ifdef WIN32
static unsigned __stdcall fn(void* arg)
#else
static void* fn(void* arg)
#endif
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
int value;
char name[100];
char **r = NULL;
EXEC SQL END DECLARE SECTION;
value = (long)arg;
sprintf(name, "Connection: %d", value);
EXEC SQL CONNECT TO REGRESSDB1 AS :name;
EXEC SQL SET AUTOCOMMIT TO ON;
for (i = 1; i <= REPEATS; ++i)
{
EXEC SQL SELECT relname INTO :r FROM pg_class WHERE relname = 'pg_class';
free(r);
r = NULL;
}
EXEC SQL DISCONNECT :name;
return 0;
}
int main ()
{
int i;
#ifdef WIN32
HANDLE threads[THREADS];
#else
pthread_t threads[THREADS];
#endif
#ifdef WIN32
for (i = 0; i < THREADS; ++i)
{
unsigned id;
threads[i] = (HANDLE)_beginthreadex(NULL, 0, fn, (void*)i, 0, &id);
}
WaitForMultipleObjects(THREADS, threads, TRUE, INFINITE);
for (i = 0; i < THREADS; ++i)
CloseHandle(threads[i]);
#else
for (i = 0; i < THREADS; ++i)
pthread_create(&threads[i], NULL, fn, (void *) (long) i);
for (i = 0; i < THREADS; ++i)
pthread_join(threads[i], NULL);
#endif
return 0;
}
#endif