[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: POSIX semaphore for GNU/Hurd
From: |
Neal H. Walfield |
Subject: |
Re: POSIX semaphore for GNU/Hurd |
Date: |
02 Nov 2002 19:45:51 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 |
> > int
> > sem_init (sem_t *sem, int pshared, unsigned int value)
> > {
> > if (pshared)
> > return -1;
>
> If you wanted to be consistant with LinuxThreads this should be
> if (pshared)
> {
> errno = ENOSYS;
> return -1;
> }
> However, I think it would be better to actually implement this
> feature.
It may be better but it is non-trivial. We do not support the process
shared attribute in pthread mutexes et al either.
> would be shorter. The real question is, are either of these implementations
> cancellable? As far as I can tell both are because pthread_cond_wait is
> cancellable.
pthread_cond_wait is a cancelation point as is sem_wait. Thus, there
should be a pthread_cleanup_push and pthread_cleanup_pop to unlock the
mutex if need be. E.g.
pthread_cleanup_push (pthread_mutex, (void *) &mutex);
...
pthread_cleanup_pop (1);
> To be paranoid, this should also contain
> if (sem->count == SEM_VALUE_MAX)
> {
> pthread_mutex_unlock (&sem->count_lock);
> return -1;
> }
Only if SEM_VALUE_MAX is defined: POSIX does not say that it has to
be.
> > /* Initialize the semaphore and set the initial value - as in LinuxThreads
> > pshared must be zero right now. */
>
> How about for a comment:
> /* Initialize the semaphore and set the initial value. PSHARED must be set
> to 0 processes sharing semaphores is not implemented yet. */
No. This is wrong. Any comment belongs in the documentation, not
here.