This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3] Make fprintf() function to multithread-safe


On 24 Jul 2012, Rich Felker outgrape:

> What I'd really prefer to see is for this entire functionality to be
> deprecated, and if it's really needed, replaced by an equivalent
> mechanism without global state in the form:
>
> printf("%Q", custom_format_object, my_data);
>
> where custom_format_object is either a pointer to a caller-filled
> structure of an opaque pointer obtained by a function to allocate a
> new printf custom formatting, and "%Q" is a random letter I made up to
> indicate to printf that it should expect such a pointer followed by a
> pointer to the actual data.
>
> This would be entirely stateless, would not run into a limit on the
> number of custom formats, and would not have libraries stepping on
> each other if/when they try to use it.

It would also allow better optimization, as right now calls to printf()
and friends have to assume that global state may be invalidated because
custom printf() handlers may do so -- even though in practice this
facility is hardly ever used, while printf()-class functions are
ubiquitous.

If printf() lost this nearly-unused ability, GCC could begin to optimize
based on the knowledge that global state must be unmodified over the
call (unless explicitly changed via e.g. taking the address of such
state and handing it to printf() in a position matched with a %n).

-- 
NULL && (void)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]