Re: Thread-safe getopt() - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Thread-safe getopt()
Date
Msg-id 600286f9-fdc3-4d6e-8458-9bfcc729d228@iki.fi
Whole thread Raw
In response to Re: Thread-safe getopt()  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Thread-safe getopt()
List pgsql-hackers
On 30/03/2026 17:34, Tom Lane wrote:
> Heikki Linnakangas <hlinnaka@iki.fi> writes:
>>>> Here's a patch for a thread-safe version of getopt(). I implemented it
>>>> as two functions, pg_getopt_start() and pg_getopt_next(). Since
>>>> there's no standard to follow, we have freedom on how to implement it,
> 
> Why in the world would we invent our own getopt API rather than
> just replacing the relevant state variables with thread-local ones,
> entirely internally to getopt.c?
> 
> It's not like this is a performance-critical code path.  I think
> the cognitive load for developers of having to learn YA API should
> weigh against doing things this way.

The new API is very similar to the same as the plain getopt() API, it'll 
be quickly recognizable to anyone who's familiar with getopt().

Thread-local variables would work too, but I think we'd need to give 
them different names anyway to avoid conflicting with the plain getopt() 
global variables.

- Heikki




pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: Changing the state of data checksums in a running cluster
Next
From: vignesh C
Date:
Subject: Re: Skipping schema changes in publication