public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* RE: [pthread-win32] Re: pthreads on Win2k
@ 2001-03-23 17:21 Bossom, John
  0 siblings, 0 replies; 4+ messages in thread
From: Bossom, John @ 2001-03-23 17:21 UTC (permalink / raw)
  To: 'rpj@ise.canberra.edu.au', Bossom, John
  Cc: 'Tristan Savatier',
	Stephen R. Johns, Steve Croall, 'John Funnell',
	'pthreads-win32@sourceware.cygnus.com'

hmmm... Ross has more books than I!

-----Original Message-----
From: Ross Johnson [ mailto:rpj@ise.canberra.edu.au ]
Sent: March 23, 2001 6:44 PM
To: Bossom, John
Cc: 'Tristan Savatier'; Stephen R. Johns; Steve Croall; 'John Funnell';
'pthreads-win32@sourceware.cygnus.com'
Subject: Re: [pthread-win32] Re: pthreads on Win2k


Hi all,

Re the use of mutex_unlock() by threads that don't own the mutex:

The standard says:

  "The function pthread_mutex_unlock() is called by the owner of the
mutex
  object ... to release it. A pthread_mutex_unlock() call by a
  thread that is not the owner of the mutex results in undefined
behavior."

And under the heading "Errors":

  "For each of the following conditions, if the condition is detected,
the
  pthread_mutex_unlock() function shall return the corresponding error
number:

    [EPERM]  The current thread does not own the mutex."

The Linux pthread_mutex_unlock() manual page states:

  "The pthread_mutex_unlock function  returns  the  following
  error code on error:
 
     EINVAL the mutex has not been properly initialized.
 
     EPERM  the calling thread does not  own  the  mutex
            (``error checking'' mutexes only)."

Note the (``error checking'' mutexes only). The default type of mutex is
what it calls "fast", with no, or limited, error checking. There are two
other
"kinds" called PTHREAD_MUTEX_ERRORCHECK_NP and
PTHREAD_MUTEX_RECURSIVE_NP.
See the manual page for pthread_mutexattr_setkind_np().

Other implementations appear to be based on the OpenGroup documentation
which is similar (Solaris, True64Unix), where again the default type
appears to be non-errorchecking, leaving it up to the programmer to 
ensure sanity prevails. See:

http://www.opengroup.org/onlinepubs/7908799/xsh/pthread_mutexattr_gettype.ht
ml

We are currently working on adding the other mutex types as defined
in the OpenGroup pthread_mutexattr_settype() manual page, as well as
providing compatibility with Linux.

Regards.
Ross

"Bossom, John" wrote:
> 
> Here are some quotes from my multitude of books on PThreads:
> 
> 1) Multithreaded Programming with PTHREADS, Bil Lewis & Daniel Berg, page
86
>     "Because mutexes protect sections of code, it is not legal for
>      one thread to lock a mutex and for another thread to unlock it.
>      Depending upon the library implementation, this might not result
>      in a runtime error, but it is illegal."
> 
> 2) Programming with POSIX Threads, Butenhof, pg 319, describing the POSIX
> 1003.1c-1995 Interfaces:
> 
>     pthread_mutex_unlock
> 
>     Errors:
>         [EPERM}    calling thread does not own mutex.
> 
> 3) Pthreads Programming, Nichols:
> 
>   "Error Detection and Return Values", pg 68
>     "The Pthreads standard allows implementations to define the exact
level
>     of error detection and reporting for some library calls. Although this
> allows
>     vendors to design efficient library calls, it can pose a particular
> problem
>     when you use mutex library calls.
>     In general, the Pthreads library reporta all errors associated with
> resource
>     availability and system constraints on function operation. For
example,
> fi the
>     library realizes that it cannot initialize a mutex for a thread
because
> the
>     library itself hasn't enough space in its internal tables, it returns
a
> value
>     of EAGAIN or ENOMEM to the caller of pthread_mutex_init. However, the
> library does
>     not have to detect improper uses of a mutex and report any errors that
> might
>     result. Such improper uses include:
>         * Locking a mutex that you have not initialized
>         * Locking a mutex that you already own
>         * Unlocking a mutex that you don't own
>     Hopefully, the library you use does detect these misuses. If it does
not
> in its
>     default mode, see if it has a debug mode that provides additional
error
> detection."
> 
> Hope this helps,
> 
> John.
> 
> -----Original Message-----
> From: Tristan Savatier [ mailto:tristan@mpegtv.com ]
> Sent: March 23, 2001 3:58 PM
> To: Stephen R. Johns
> Cc: Steve Croall; 'John Funnell'; 'pthreads-win32@sourceware.cygnus.com'
> Subject: Re: [pthread-win32] Re: pthreads on Win2k
> 
> Stephen R. Johns wrote:
> >
> > Probably not related, but just in case...
> >
> > I've been trying to port a linux program to pthreadw32, and found
> > a mutex issue/difference.
> >
> > Linux allows threads other than the locking thread to unlock a mutex,
> > but pthreads does not.
> 
> I don't recall that the POSIX standard places a restriction on
> which thread can unlock a mutex, but it does not look like good
> programming style to have a mutex locked and unlocked by different
> threads..
> 
> If posix-thread places a restriction that is not defined by the
> standard, it should be documented.  It does not look like this
> one is a real problem... looks like POSIX should have put the
> restriction in the standard!  I suppose that the underlying win32
> threads do have this restriction.
> 
> -t

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pthread-win32] Re: pthreads on Win2k
  2001-03-23 13:35 Bossom, John
@ 2001-03-23 15:58 ` Ross Johnson
  0 siblings, 0 replies; 4+ messages in thread
From: Ross Johnson @ 2001-03-23 15:58 UTC (permalink / raw)
  To: Bossom, John
  Cc: 'Tristan Savatier',
	Stephen R. Johns, Steve Croall, 'John Funnell',
	'pthreads-win32@sourceware.cygnus.com'

Hi all,

Re the use of mutex_unlock() by threads that don't own the mutex:

The standard says:

  "The function pthread_mutex_unlock() is called by the owner of the
mutex
  object ... to release it. A pthread_mutex_unlock() call by a
  thread that is not the owner of the mutex results in undefined
behavior."

And under the heading "Errors":

  "For each of the following conditions, if the condition is detected,
the
  pthread_mutex_unlock() function shall return the corresponding error
number:

    [EPERM]  The current thread does not own the mutex."

The Linux pthread_mutex_unlock() manual page states:

  "The pthread_mutex_unlock function  returns  the  following
  error code on error:
 
     EINVAL the mutex has not been properly initialized.
 
     EPERM  the calling thread does not  own  the  mutex
            (``error checking'' mutexes only)."

Note the (``error checking'' mutexes only). The default type of mutex is
what it calls "fast", with no, or limited, error checking. There are two
other
"kinds" called PTHREAD_MUTEX_ERRORCHECK_NP and
PTHREAD_MUTEX_RECURSIVE_NP.
See the manual page for pthread_mutexattr_setkind_np().

Other implementations appear to be based on the OpenGroup documentation
which is similar (Solaris, True64Unix), where again the default type
appears to be non-errorchecking, leaving it up to the programmer to 
ensure sanity prevails. See:

http://www.opengroup.org/onlinepubs/7908799/xsh/pthread_mutexattr_gettype.html

We are currently working on adding the other mutex types as defined
in the OpenGroup pthread_mutexattr_settype() manual page, as well as
providing compatibility with Linux.

Regards.
Ross

"Bossom, John" wrote:
> 
> Here are some quotes from my multitude of books on PThreads:
> 
> 1) Multithreaded Programming with PTHREADS, Bil Lewis & Daniel Berg, page 86
>     "Because mutexes protect sections of code, it is not legal for
>      one thread to lock a mutex and for another thread to unlock it.
>      Depending upon the library implementation, this might not result
>      in a runtime error, but it is illegal."
> 
> 2) Programming with POSIX Threads, Butenhof, pg 319, describing the POSIX
> 1003.1c-1995 Interfaces:
> 
>     pthread_mutex_unlock
> 
>     Errors:
>         [EPERM}    calling thread does not own mutex.
> 
> 3) Pthreads Programming, Nichols:
> 
>   "Error Detection and Return Values", pg 68
>     "The Pthreads standard allows implementations to define the exact level
>     of error detection and reporting for some library calls. Although this
> allows
>     vendors to design efficient library calls, it can pose a particular
> problem
>     when you use mutex library calls.
>     In general, the Pthreads library reporta all errors associated with
> resource
>     availability and system constraints on function operation. For example,
> fi the
>     library realizes that it cannot initialize a mutex for a thread because
> the
>     library itself hasn't enough space in its internal tables, it returns a
> value
>     of EAGAIN or ENOMEM to the caller of pthread_mutex_init. However, the
> library does
>     not have to detect improper uses of a mutex and report any errors that
> might
>     result. Such improper uses include:
>         * Locking a mutex that you have not initialized
>         * Locking a mutex that you already own
>         * Unlocking a mutex that you don't own
>     Hopefully, the library you use does detect these misuses. If it does not
> in its
>     default mode, see if it has a debug mode that provides additional error
> detection."
> 
> Hope this helps,
> 
> John.
> 
> -----Original Message-----
> From: Tristan Savatier [ mailto:tristan@mpegtv.com ]
> Sent: March 23, 2001 3:58 PM
> To: Stephen R. Johns
> Cc: Steve Croall; 'John Funnell'; 'pthreads-win32@sourceware.cygnus.com'
> Subject: Re: [pthread-win32] Re: pthreads on Win2k
> 
> Stephen R. Johns wrote:
> >
> > Probably not related, but just in case...
> >
> > I've been trying to port a linux program to pthreadw32, and found
> > a mutex issue/difference.
> >
> > Linux allows threads other than the locking thread to unlock a mutex,
> > but pthreads does not.
> 
> I don't recall that the POSIX standard places a restriction on
> which thread can unlock a mutex, but it does not look like good
> programming style to have a mutex locked and unlocked by different
> threads..
> 
> If posix-thread places a restriction that is not defined by the
> standard, it should be documented.  It does not look like this
> one is a real problem... looks like POSIX should have put the
> restriction in the standard!  I suppose that the underlying win32
> threads do have this restriction.
> 
> -t

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [pthread-win32] Re: pthreads on Win2k
@ 2001-03-23 13:35 Bossom, John
  2001-03-23 15:58 ` Ross Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: Bossom, John @ 2001-03-23 13:35 UTC (permalink / raw)
  To: 'Tristan Savatier', Stephen R. Johns
  Cc: Steve Croall, 'John Funnell',
	'pthreads-win32@sourceware.cygnus.com'

Here are some quotes from my multitude of books on PThreads:

1) Multithreaded Programming with PTHREADS, Bil Lewis & Daniel Berg, page 86
    "Because mutexes protect sections of code, it is not legal for
     one thread to lock a mutex and for another thread to unlock it.
     Depending upon the library implementation, this might not result
     in a runtime error, but it is illegal."

2) Programming with POSIX Threads, Butenhof, pg 319, describing the POSIX
1003.1c-1995 Interfaces:

    pthread_mutex_unlock

    Errors:
        [EPERM}    calling thread does not own mutex.



3) Pthreads Programming, Nichols:

  "Error Detection and Return Values", pg 68
    "The Pthreads standard allows implementations to define the exact level
    of error detection and reporting for some library calls. Although this
allows
    vendors to design efficient library calls, it can pose a particular
problem
    when you use mutex library calls.
    In general, the Pthreads library reporta all errors associated with
resource
    availability and system constraints on function operation. For example,
fi the
    library realizes that it cannot initialize a mutex for a thread because
the
    library itself hasn't enough space in its internal tables, it returns a
value 
    of EAGAIN or ENOMEM to the caller of pthread_mutex_init. However, the
library does
    not have to detect improper uses of a mutex and report any errors that
might
    result. Such improper uses include:
        * Locking a mutex that you have not initialized
        * Locking a mutex that you already own
        * Unlocking a mutex that you don't own
    Hopefully, the library you use does detect these misuses. If it does not
in its
    default mode, see if it has a debug mode that provides additional error
detection."


Hope this helps,

John.


-----Original Message-----
From: Tristan Savatier [ mailto:tristan@mpegtv.com ]
Sent: March 23, 2001 3:58 PM
To: Stephen R. Johns
Cc: Steve Croall; 'John Funnell'; 'pthreads-win32@sourceware.cygnus.com'
Subject: Re: [pthread-win32] Re: pthreads on Win2k


Stephen R. Johns wrote:
> 
> Probably not related, but just in case...
> 
> I've been trying to port a linux program to pthreadw32, and found
> a mutex issue/difference.
> 
> Linux allows threads other than the locking thread to unlock a mutex,
> but pthreads does not.

I don't recall that the POSIX standard places a restriction on
which thread can unlock a mutex, but it does not look like good
programming style to have a mutex locked and unlocked by different
threads..

If posix-thread places a restriction that is not defined by the
standard, it should be documented.  It does not look like this
one is a real problem... looks like POSIX should have put the
restriction in the standard!  I suppose that the underlying win32
threads do have this restriction.

-t

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pthread-win32] Re: pthreads on Win2k
  2001-03-23  6:31 ` Stephen R. Johns
@ 2001-03-23 12:58   ` Tristan Savatier
  0 siblings, 0 replies; 4+ messages in thread
From: Tristan Savatier @ 2001-03-23 12:58 UTC (permalink / raw)
  To: Stephen R. Johns
  Cc: Steve Croall, 'John Funnell',
	'pthreads-win32@sourceware.cygnus.com'

Stephen R. Johns wrote:
> 
> Probably not related, but just in case...
> 
> I've been trying to port a linux program to pthreadw32, and found
> a mutex issue/difference.
> 
> Linux allows threads other than the locking thread to unlock a mutex,
> but pthreads does not.

I don't recall that the POSIX standard places a restriction on
which thread can unlock a mutex, but it does not look like good
programming style to have a mutex locked and unlocked by different
threads..

If posix-thread places a restriction that is not defined by the
standard, it should be documented.  It does not look like this
one is a real problem... looks like POSIX should have put the
restriction in the standard!  I suppose that the underlying win32
threads do have this restriction.

-t

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-03-23 17:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-23 17:21 [pthread-win32] Re: pthreads on Win2k Bossom, John
  -- strict thread matches above, loose matches on Subject: below --
2001-03-23 13:35 Bossom, John
2001-03-23 15:58 ` Ross Johnson
2001-03-23  1:35 Steve Croall
2001-03-23  6:31 ` Stephen R. Johns
2001-03-23 12:58   ` [pthread-win32] " Tristan Savatier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).