Bug 30464 - [patch] pthread mutex attributes -- pshared
Summary: [patch] pthread mutex attributes -- pshared
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: 4.3-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-threads (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-09-09 20:50 UTC by Steve Watt
Modified: 2017-05-17 13:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Watt 2001-09-09 20:50:01 UTC
The pshared attribute is not mentioned on the pthread_mutexattr_* manual page, although "man pthread_mutexattr_getpshared" gets you that page.

Also, the functions pthread_mutexattr_{get,set}pshared are not implemented, even though POSIX requires them (yes, even if you don't support anything but PTHREAD_PROCESS_PRIVATE).

Fix: 

Add the pthread_mutexattr_{g,s}etpshared() functions, just like the rwlock has.

Add mention of them to the man page.
How-To-Repeat: man pthread_mutexattr_getpshared
search for pshared

Attempt to compile the following program:
#include <pthread.h>

int main(int argc, char **argv) {
    pthread_mutexattr_t ma;

    pthread_mutexattr_init(&ma);
    pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_PRIVATE);

    exit(0);
}
Comment 1 Jason Evans freebsd_committer 2001-12-17 20:42:17 UTC
Responsible Changed
From-To: freebsd-bugs->jasone

I'll look at this.
Comment 2 Jason Evans freebsd_committer 2002-05-11 23:23:41 UTC
Responsible Changed
From-To: jasone->freebsd-bugs
Comment 3 Chris Knight 2002-06-20 08:02:47 UTC
Howdy,

The following patch should help.
I created it based on the prototypes in /usr/include/pthread.h and by looking
at similar code in the devel/linuxthreads port and the Darwin CVS repository.
Feel free to make it look like the functions in uthread_rwlockattr.c if you
like.

Regards,
Chris Knight

--- lib/libc_r/uthread/Makefile.inc.old	Wed Sep 20 21:28:52 2000
+++ lib/libc_r/uthread/Makefile.inc	Thu Jun 20 16:47:39 2002
@@ -31,6 +31,7 @@
 	uthread_cond.c \
 	uthread_condattr_destroy.c \
 	uthread_condattr_init.c \
+	uthread_condattr_pshared.c \
 	uthread_connect.c \
 	uthread_creat.c \
 	uthread_create.c \
@@ -77,6 +78,7 @@
 	uthread_mutex_prioceiling.c \
 	uthread_mutex_protocol.c \
 	uthread_mutexattr_destroy.c \
+	uthread_mutexattr_pshared.c \
 	uthread_nanosleep.c \
 	uthread_once.c \
 	uthread_open.c \
--- /dev/null	Thu Jun 20 16:03:00 2002
+++ lib/libc_r/uthread/uthread_condattr_pshared.c	Thu Jun 20 16:34:23 2002
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2002 Chris Knight <chris@aims.com.au>.
+ * 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(s), this list of conditions and the following disclaimer as
+ *    the first lines of this file unmodified other than the possible
+ *    addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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 <stdlib.h>
+#include <errno.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+#if defined(_POSIX_THREAD_PROCESS_SHARED)
+int
+pthread_condattr_getpshared(pthread_condattr_t *attr, int *pshared)
+{
+	/* not possible to share a condvar, return private */
+	*pshared = PTHREAD_PROCESS_PRIVATE;
+	return (ESUCCESS);
+}
+
+int
+pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared)
+{
+	int	ret = EINVAL;
+
+	/* not possible to share a condvar, return success if set private */
+	if (pshared == PTHREAD_PROCESS_PRIVATE)
+		ret = ESUCCESS;
+	return (ret);
+}
+#endif
+#endif
--- /dev/null	Thu Jun 20 16:03:00 2002
+++ lib/libc_r/uthread/uthread_mutexattr_pshared.c	Thu Jun 20 16:36:55 2002
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2002 Chris Knight <chris@aims.com.au>.
+ * 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(s), this list of conditions and the following disclaimer as
+ *    the first lines of this file unmodified other than the possible
+ *    addition of one or more copyright notices.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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 <stdlib.h>
+#include <errno.h>
+#ifdef _THREAD_SAFE
+#include <pthread.h>
+#include "pthread_private.h"
+
+#if defined(_POSIX_THREAD_PROCESS_SHARED)
+int
+pthread_mutexattr_getpshared(pthread_mutexattr_t *attr, int *pshared)
+{
+	/* not possible to share a mutex, return private */
+	*pshared = PTHREAD_PROCESS_PRIVATE;
+	return (ESUCCESS);
+}
+
+int
+pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
+{
+	int	ret = EINVAL;
+
+	/* not possible to share a mutex, return success if set private */
+	if (pshared == PTHREAD_PROCESS_PRIVATE)
+		ret = ESUCCESS;
+	return (ret);
+}
+#endif
+#endif
Comment 4 Kris Kennaway freebsd_committer 2003-07-13 02:40:34 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-threads

Assign to threads mailing list
Comment 5 Maxim Konovalov freebsd_committer 2006-04-24 20:30:48 UTC
State Changed
From-To: open->suspended

Awaiting patches.
Comment 6 Ed Maste freebsd_committer 2016-02-29 15:14:00 UTC
See r296162