Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #27567

Re: How to apply qsort() with a parameter?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.c
Subject Re: How to apply qsort() with a parameter?
Date 2012-10-23 08:14 -0400
Organization A noiseless patient Spider
Message-ID <k661o1$mfa$1@dont-email.me> (permalink)
References (1 earlier) <k6441n$oa7$1@dont-email.me> <k6452n$vb3$1@dont-email.me> <3606b512-c0d2-444b-8547-d3013cf8d0db@n16g2000yqi.googlegroups.com> <k64bpp$o0d$1@dont-email.me> <cg6c88prcp40kt0av5fmk7beq0chctf916@4ax.com>

Show all headers | View raw


On 10/23/2012 12:25 AM, Robert Wessel wrote:
>[...]
>>      Since qsort() itself need not be thread-safe (it need not
>> even be re-entrant within just one thread), the thread-safety
>> of a comparator scarcely matters.  A thread-safe comparator
>> could be called by qsort() in one thread while another called
>> it via bsearch(), but that's a bit of a stretch.
>
> How is qsort not thread safe or non-reentrant?  With the obvious, and
> uninteresting, exception of an attempt to simultaneously sort a single
> array more than once.

     7.1.4p4: "The functions in the standard library are not
guaranteed to be reentrant and may modify objects with static
or thread storage duration."

     Even so, it turns out I was wrong, at least in part.  The
quoted language appears in both C99 (except for "or thread") and
C11, but C11 adds two further paragraphs p6,p7 describing some
thread-safety constraints on implementations of the library.
"Upon further review," I now believe

	In C11, qsort() is thread-safe.

	In C99, qsort() is thread-UNsafe (sort of obvious, since
	C99 has no notion of threads).

	In both C99 and C11, qsort() is non-reentrant.  Two C11
	threads can use qsort() simultaneously, but it's still
	an error to call qsort() from qsort()'s comparator, or
	to call it from a handler for a signal that might be
	raised during a qsort().

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to apply qsort() with a parameter? rouben@shadow.(none) (Rouben Rostamian) - 2012-10-22 17:51 +0000
  Re: How to apply qsort() with a parameter? ImpalerCore <jadill33@gmail.com> - 2012-10-22 11:18 -0700
    Re: How to apply qsort() with a parameter? ImpalerCore <jadill33@gmail.com> - 2012-10-22 11:26 -0700
    Re: How to apply qsort() with a parameter? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 20:27 +0100
  Re: How to apply qsort() with a parameter? tom st denis <tom@iahu.ca> - 2012-10-22 11:38 -0700
  Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 14:41 -0400
    Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 14:59 -0400
      Re: How to apply qsort() with a parameter? tom st denis <tom@iahu.ca> - 2012-10-22 13:25 -0700
        Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 16:54 -0400
          Re: How to apply qsort() with a parameter? Robert Wessel <robertwessel2@yahoo.com> - 2012-10-22 23:25 -0500
            Re: How to apply qsort() with a parameter? James Kuyper <jameskuyper@verizon.net> - 2012-10-23 07:42 -0400
            Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-23 08:14 -0400
          Re: How to apply qsort() with a parameter? tom st denis <tom@iahu.ca> - 2012-10-23 07:05 -0700
            Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-23 10:13 -0400
    Re: How to apply qsort() with a parameter? "Scott Fluhrer" <sfluhrer@ix.netcom.com> - 2012-10-23 10:28 -0400
      Re: How to apply qsort() with a parameter? Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-23 10:56 -0400
  Re: How to apply qsort() with a parameter? Öö Tiib <ootiib@hot.ee> - 2012-10-22 15:30 -0700
  Re: How to apply qsort() with a parameter? rouben@shady.(none) (Rouben Rostamian) - 2012-10-23 03:52 +0000
    Re: How to apply qsort() with a parameter? Keith Thompson <kst-u@mib.org> - 2012-10-22 22:46 -0700
      Re: How to apply qsort() with a parameter? pete <pfiland@mindspring.com> - 2012-10-23 16:03 -0400
    Re: How to apply qsort() with a parameter? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-10-23 06:43 -0700

csiph-web