Loading...
--- /dev/null
+++ Libc/Libc-583/stdlib/psort.3
@@ -0,0 +1,133 @@
+.\" Copyright (c) 1990, 1991, 1993
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software contributed to Berkeley by
+.\" the American National Standards Committee X3, on Information
+.\" Processing Systems.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.15 2004/07/02 23:52:12 ru Exp $
+.\"
+.Dd Nov 25, 2008
+.Dt PSORT 3
+.Os "Mac OS X"
+.Sh NAME
+.Nm psort ,
+#ifdef UNIFDEF_BLOCKS
+.Nm psort_b ,
+#endif
+.Nm psort_r
+.Nd parallel sort functions
+.Sh SYNOPSIS
+.In stdlib.h
+.Ft void
+.Fo psort
+.Fa "void *base"
+.Fa "size_t nel"
+.Fa "size_t width"
+.Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
+.Fc
+#ifdef UNIFDEF_BLOCKS
+.Ft void
+.Fo psort_b
+.Fa "void *base"
+.Fa "size_t nel"
+.Fa "size_t width"
+.Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]"
+.Fc
+#endif
+.Ft void
+.Fo psort_r
+.Fa "void *base"
+.Fa "size_t nel"
+.Fa "size_t width"
+.Fa "void *thunk"
+.Fa "int \*[lp]*compar\*[rp]\*[lp]void *, const void *, const void *\*[rp]"
+.Fc
+.Sh DESCRIPTION
+The
+#ifdef UNIFDEF_BLOCKS
+.Fn psort ,
+.Fn psort_b ,
+#else
+.Fn psort
+#endif
+and
+.Fn psort_r
+functions are parallel sort routines that are drop-in compatible with the
+corresponding
+.Fn qsort
+function (see
+.Xr qsort 3
+for a description of the arguments).
+On multiprocessor machines, multiple threads may be created to simultaneously
+perform the sort calculations, resulting in an overall faster sort result.
+Overhead in managing the threads limits the maximum speed improvement to
+somewhat less that the number of processors available.
+For example, on a 4-processor machine, a typical sort on a large array might
+result in 3.2 times faster sorting than a regular
+.Fn qsort .
+.Sh RESTRICTIONS
+Because of the multi-threaded nature of the sort, the comparison function
+is expected to perform its own synchronization that might be required for
+data physically
+.Em outside
+the two objects passed to the comparison function.
+However, no synchronization is required for the two
+object themselves, unless some third party is also accessing those objects.
+.Pp
+Additional memory is temporary allocated to deal with the parallel nature
+of the computation.
+.Pp
+Because of the overhead of maintaining multiple threads, the
+.Fn psort
+family of routines may choose to just call
+.Xr qsort 3
+when there is no advantage to parallelizing (for example, when the number of
+objects in the array is too small, or only one processor is available).
+.Pp
+Like
+.Xr qsort 3 ,
+the sort is not stable.
+.Sh RETURN VALUES
+The
+#ifdef UNIFDEF_BLOCKS
+.Fn psort ,
+.Fn psort_b
+#else
+.Fn psort
+#endif
+and
+.Fn psort_r
+functions
+return no value.
+.Sh SEE ALSO
+.Xr qsort 3