standards/50848: [PATCH] Implementation of pthread_[get|set]concurrency

Sergey A.Osokin osa at FreeBSD.org.ru
Sat Apr 12 01:40:12 PDT 2003


>Number:         50848
>Category:       standards
>Synopsis:       [PATCH] Implementation of pthread_[get|set]concurrency
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Apr 12 01:40:07 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Sergey A. Osokin
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
n/a
>Environment:
System: FreeBSD 5.0-CURRENT #30: Mon Mar 31 15:10:23 MSD 2003 i386

>Description:
	Implementation of pthread_[get|set]concurrency
	SUSv2 tell:
	"If an implementation does not support multiplexing
         of user threads on top of several kernel scheduled
         entities, the pthread_setconcurrency() and
         pthread_getconcurrency() functions will be provided
         for source code compatibility but they will have no
         effect when called."
>How-To-Repeat:
>Fix:

Index: src/lib/libc_r/uthread/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/uthread/Makefile.inc,v
retrieving revision 1.35
diff -u -r1.35 Makefile.inc
--- src/lib/libc_r/uthread/Makefile.inc	11 Feb 2003 07:28:28 -0000	1.35
+++ src/lib/libc_r/uthread/Makefile.inc	11 Apr 2003 22:02:33 -0000
@@ -37,6 +37,7 @@
 	uthread_cancel.c \
 	uthread_clean.c \
 	uthread_close.c \
+	uthread_concurrency.c \
 	uthread_cond.c \
 	uthread_condattr_destroy.c \
 	uthread_condattr_init.c \
Index: src/lib/libc_r/man/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libc_r/man/Makefile.inc,v
retrieving revision 1.19
diff -u -r1.19 Makefile.inc
--- src/lib/libc_r/man/Makefile.inc	24 Feb 2003 22:59:01 -0000	1.19
+++ src/lib/libc_r/man/Makefile.inc	11 Apr 2003 22:02:34 -0000
@@ -10,6 +10,7 @@
 	pthread_cancel.3 \
 	pthread_cleanup_pop.3 \
 	pthread_cleanup_push.3 \
+	pthread_getconcurrency.3 \
 	pthread_condattr.3 \
 	pthread_cond_broadcast.3 \
 	pthread_cond_destroy.3 \
@@ -85,6 +86,7 @@
 	pthread_attr.3 pthread_attr_setstack.3 \
 	pthread_attr.3 pthread_attr_setstackaddr.3 \
 	pthread_attr.3 pthread_attr_setstacksize.3 \
+	pthread_getconcurrency.3 pthread_setconcurrency.3 \
 	pthread_condattr.3 pthread_condattr_init.3 \
 	pthread_condattr.3 pthread_condattr_destroy.3 \
 	pthread_multi_np.3 pthread_single_np.3 \
--- /dev/null	Fri Apr 11 18:07:14 2003
+++ src/lib/libc_r/uthread/uthread_concurrency.c	Sat Apr 12 01:30:30 2003
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2003 Sergey Osokin <osa at FreeBSD.org.ru>.
+ * All rights reserved.
+ *
+ * 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 Sergey Osokin.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <errno.h>
+
+__weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
+__weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
+
+int
+_pthread_getconcurrency(void)
+{
+	return 0;
+}
+
+int
+_pthread_setconcurrency(int new_level)
+{
+	if (new_level < 0) {
+		errno = EINVAL;
+		return (-1);
+	}
+	return 0;
+}
--- /dev/null	Fri Apr 11 18:07:14 2003
+++ src/lib/libc_r/man/pthread_getconcurrency.3	Fri Apr 11 20:24:04 2003
@@ -0,0 +1,108 @@
+.\" Copyright (c) 2003 Sergey Osokin <osa at FreeBSD.org.ru>
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.Dd April 11, 2003
+.Dt PTHREAD_GETCONCURRENCY 3
+.Os
+.Sh NAME
+.Nm pthread_getconcurrency,
+.Nm pthread_setconcurrency
+.Nd get or set level of concurrency
+.Sh LIBRARY
+.Lb libc_r
+.Sh SYNOPSIS
+.In pthread.h
+.Ft int
+.Fn pthread_getconcurrency "void"
+.Ft int
+.Fn pthread_setconcurrency "int new_level"
+.Sh DESCRIPTION
+The
+.Fn pthread_getconcurrency
+function allows an application to inform the threads implementation
+of its desired concurrency level,
+.Va new_level .
+The actual level of concurrency provided by the implementation
+as a result of this function call is unspecified.  If new_level is
+zero, it causes the implementation to maintain the concurrency
+level at its discretion as if
+.Fn pthread_setconcurrency
+was never called.  The
+.Fn pthread_getconcurrency
+function returns the value set by a previous call to the
+.Fn pthread_setconcurrency
+function. If the
+.Fn pthread_setconcurrency
+function was not previously called, this function returns zero to
+indicate that the implementation is maintaining the concurrency
+level.  When an application calls
+.Fn pthread_setconcurrency
+it is informing the implementation of its desired concurrency
+level.  The implementation uses this as a hint, not a requirement.
+.Sh RETURN VALUES
+If successful, the
+.Fn pthread_setconcurrency
+function returns zero. Otherwise, an error number is returned
+to indicate the error.  The
+.Fn pthread_getconcurrency
+function always returns the concurrency level set by a previous
+call to
+.Fn pthread_setconcurrency .
+If the
+.Fn pthread_setconcurrency
+function has never been called,
+.Fn pthread_getconcurrency
+returns zero.
+.Sh ERRORS
+The
+.Fn pthread_setconcurrency
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The value specified by
+.Va new_level
+is negative.
+.El
+.Bl -tag -width Er
+.It Bq Er EAGAIN
+The value specific by
+.Va new_level
+would cause a system resource to be exceeded.
+.Sh APPLICATION USAGE
+Use of these functions changes the state of the underlying
+concurrency upon which the application depends.  Library
+developers are advised to not use the
+.Fn pthread_getconcurrency
+and
+.Fn pthread_setconcurrency
+functions since their use may conflict with an applications
+use of these functions.
+.Sh STANDARDS
+The
+.Fn pthread_getconcurrency
+and
+.Fn pthread_setconcurrency
+functions conform to
+.St -susv2
Index: src/lib/libpthread/man/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libpthread/man/Makefile.inc,v
retrieving revision 1.16
diff -u -r1.16 Makefile.inc
--- src/lib/libpthread/man/Makefile.inc	3 Mar 2003 22:40:20 -0000	1.16
+++ src/lib/libpthread/man/Makefile.inc	11 Apr 2003 22:02:34 -0000
@@ -9,6 +9,7 @@
 	pthread_cancel.3 \
 	pthread_cleanup_pop.3 \
 	pthread_cleanup_push.3 \
+	pthread_getconcurrency.3 \
 	pthread_condattr.3 \
 	pthread_cond_broadcast.3 \
 	pthread_cond_destroy.3 \
@@ -73,6 +74,7 @@
 	pthread_attr.3 pthread_attr_setscope.3 \
 	pthread_attr.3 pthread_attr_setstackaddr.3 \
 	pthread_attr.3 pthread_attr_setstacksize.3 \
+	pthread_getconcurrency.3 pthread_setconcurrency.3 \
 	pthread_condattr.3 pthread_condattr_init.3 \
 	pthread_condattr.3 pthread_condattr_destroy.3 \
 	pthread_mutexattr.3 pthread_mutexattr_init.3 \
Index: src/lib/libpthread/thread/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libpthread/thread/Makefile.inc,v
retrieving revision 1.38
diff -u -r1.38 Makefile.inc
--- src/lib/libpthread/thread/Makefile.inc	3 Mar 2003 22:40:20 -0000	1.38
+++ src/lib/libpthread/thread/Makefile.inc	11 Apr 2003 22:02:35 -0000
@@ -31,6 +31,7 @@
 	thr_cancel.c \
 	thr_clean.c \
 	thr_close.c \
+	thr_concurrency.c \
 	thr_cond.c \
 	thr_condattr_destroy.c \
 	thr_condattr_init.c \
--- /dev/null	Fri Apr 11 18:07:14 2003
+++ src/lib/libpthread/thread/thr_concurrency.c	Sat Apr 12 01:32:38 2003
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2003 Sergey Osokin <osa at FreeBSD.org.ru>.
+ * All rights reserved.
+ *
+ * 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 Sergey Osokin.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <errno.h>
+
+__weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
+__weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
+
+int
+_pthread_getconcurrency(void)
+{
+	return 0;
+}
+
+int
+_pthread_setconcurrency(int new_level)
+{
+	if (new_level < 0) {
+		errno = EINVAL;
+		return (-1);
+	}
+	return 0;
+}
--- /dev/null	Fri Apr 11 18:07:14 2003
+++ src/lib/libpthread/man/pthread_getconcurrency.3	Fri Apr 11 20:41:04 2003
@@ -0,0 +1,108 @@
+.\" Copyright (c) 2003 Sergey Osokin <osa at FreeBSD.org.ru>
+.\" All rights reserved.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
+.\"
+.\" $FreeBSD$
+.Dd April 11, 2003
+.Dt PTHREAD_GETCONCURRENCY 3
+.Os
+.Sh NAME
+.Nm pthread_getconcurrency,
+.Nm pthread_setconcurrency
+.Nd get or set level of concurrency
+.Sh LIBRARY
+.Lb libc_r
+.Sh SYNOPSIS
+.In pthread.h
+.Ft int
+.Fn pthread_getconcurrency "void"
+.Ft int
+.Fn pthread_setconcurrency "int new_level"
+.Sh DESCRIPTION
+The
+.Fn pthread_getconcurrency
+function allows an application to inform the threads implementation
+of its desired concurrency level,
+.Va new_level .
+The actual level of concurrency provided by the implementation
+as a result of this function call is unspecified.  If new_level is
+zero, it causes the implementation to maintain the concurrency
+level at its discretion as if
+.Fn pthread_setconcurrency
+was never called.  The
+.Fn pthread_getconcurrency
+function returns the value set by a previous call to the
+.Fn pthread_setconcurrency
+function. If the
+.Fn pthread_setconcurrency
+function was not previously called, this function returns zero to
+indicate that the implementation is maintaining the concurrency
+level.  When an application calls
+.Fn pthread_setconcurrency
+it is informing the implementation of its desired concurrency
+level.  The implementation uses this as a hint, not a requirement.
+.Sh RETURN VALUES
+If successful, the
+.Fn pthread_setconcurrency
+function returns zero. Otherwise, an error number is returned
+to indicate the error.  The
+.Fn pthread_getconcurrency
+function always returns the concurrency level set by a previous
+call to
+.Fn pthread_setconcurrency .
+If the
+.Fn pthread_setconcurrency
+function has never been called,
+.Fn pthread_getconcurrency
+returns zero.
+.Sh ERRORS
+The
+.Fn pthread_setconcurrency
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er EINVAL
+The value specified by
+.Va new_level
+is negative.
+.El
+.Bl -tag -width Er
+.It Bq Er EAGAIN
+The value specific by
+.Va new_level
+would cause a system resource to be exceeded.
+.Sh APPLICATION USAGE
+Use of these functions changes the state of the underlying
+concurrency upon which the application depends.  Library
+developers are advised to not use the
+.Fn pthread_getconcurrency
+and
+.Fn pthread_setconcurrency
+functions since their use may conflict with an applications
+use of these functions.
+.Sh STANDARDS
+The
+.Fn pthread_getconcurrency
+and
+.Fn pthread_setconcurrency
+functions conform to
+.St -susv2
Index: src/lib/libthr/thread/Makefile.inc
===================================================================
RCS file: /home/ncvs/src/lib/libthr/thread/Makefile.inc,v
retrieving revision 1.1
diff -u -r1.1 Makefile.inc
--- src/lib/libthr/thread/Makefile.inc	1 Apr 2003 03:46:28 -0000	1.1
+++ src/lib/libthr/thread/Makefile.inc	11 Apr 2003 22:02:36 -0000
@@ -8,6 +8,7 @@
 	thr_autoinit.c \
 	thr_cancel.c \
 	thr_clean.c \
+	thr_concurrency.c \
 	thr_cond.c \
 	thr_condattr_destroy.c \
 	thr_condattr_init.c \
--- /dev/null	Fri Apr 11 18:07:14 2003
+++ src/lib/libthr/thread/thr_concurrency.c	Sat Apr 12 01:38:12 2003
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2003 Sergey Osokin <osa at FreeBSD.org.ru>.
+ * All rights reserved.
+ *
+ * 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 Sergey Osokin.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY SERGEY OSOKIN 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 AUTHOR 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <errno.h>
+
+__weak_reference(_pthread_getconcurrency, pthread_getconcurrency);
+__weak_reference(_pthread_setconcurrency, pthread_setconcurrency);
+
+int
+_pthread_getconcurrency(void)
+{
+	return 0;
+}
+
+int
+_pthread_setconcurrency(int new_level)
+{
+	if (new_level < 0) {
+		errno = EINVAL;
+		return (-1);
+	}
+	return 0;
+}

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-standards mailing list