# Optional nowait argument to sem_acquire

- Thread: https://externals.io/message/77035
- Original archive: https://news-web.php.net/php.internals/77035
- Started by Matteo Beccati on 2014-09-02T12:50:29+00:00
- Messages: 8
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #77035 — Matteo Beccati — 2014-09-02T12:50:29+00:00

URL: https://externals.io/message/77035#77035

Hi everyone,

the following patch:

https://github.com/php/php-src/pull/741

has been lying around somewhere on my box since years and I recently
stumbled upon it.

However 5.6 was already RC and Ferenc suggested to eventually wait for
5.6.1.

Do you think it's ok to add such a minor feature to 5.6.1?


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #77037 — guilhermeblanco@gmail.com — 2014-09-02T13:38:37+00:00

URL: https://externals.io/message/77035#77037 · In reply to: #77035

Hi,

Since I don't know where you guys like to discuss implementations, I'm
pasting same thing I did in php-src PR:

 I'd propose instead of accepting "nowait" only, I'd use a better support
and accept "until", dealing with possible cases:

   - -1: Blocks and wait until lock is acquired
   - 0: Exactly what your patch does, attempt to grab and if it fails, just
   return false (I'd remove the E_WARNING)
   - > 0: Acceptable time in milliseconds it would wait until consider the
   acquire failed


Cheers,





> Hi everyone,
>
> the following patch:
>
> https://github.com/php/php-src/pull/741
>
> has been lying around somewhere on my box since years and I recently
> stumbled upon it.
>
> However 5.6 was already RC and Ferenc suggested to eventually wait for
> 5.6.1.
>
> Do you think it's ok to add such a minor feature to 5.6.1?
>
>
> Cheers
> --
> Matteo Beccati
>
> Development & Consulting - http://www.beccati.com/
>
> --
> 
> 
>
>


-- 
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada

---

## #77038 — Matteo Beccati — 2014-09-02T14:01:04+00:00

URL: https://externals.io/message/77035#77038 · In reply to: #77037

Hi,


> I'd propose instead of accepting "nowait" only, I'd use a better support
> and accept "until", dealing with possible cases:
> 
>   * -1: Blocks and wait until lock is acquired
>   * 0: Exactly what your patch does, attempt to grab and if it fails,
>     just return false (I'd remove the E_WARNING)

(It doesn't. The warning is raised when the semaphore can't be acquired
for other reasons)

>   * > 0: Acceptable time in milliseconds it would wait until consider
>     the acquire failed

TBH, I don't know. semtimedop is not universally available (no BSD, as
far as I can tell) and I would prefer to avoid writing an alternative
implementation in case it's not available. On the other hand triggering
an error in such case wouldn't be nice.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #77039 — guilhermeblanco@gmail.com — 2014-09-02T14:39:02+00:00

URL: https://externals.io/message/77035#77039 · In reply to: #77038

Hi Matteo,

BSD does accept it as sem_timedwait, which I could find a reference for
FreeBSD:

http://www.freebsd.org/cgi/man.cgi?query=sema&sektion=9

Cheers,




> Hi,
>
> 
> > […]
>
> (It doesn't. The warning is raised when the semaphore can't be acquired
> for other reasons)
>
> > […]
>
> TBH, I don't know. semtimedop is not universally available (no BSD, as
> far as I can tell) and I would prefer to avoid writing an alternative
> implementation in case it's not available. On the other hand triggering
> an error in such case wouldn't be nice.
>
>
> Cheers
> --
> Matteo Beccati
>
> Development & Consulting - http://www.beccati.com/
>



-- 
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada

---

## #77040 — Matteo Beccati — 2014-09-02T14:46:56+00:00

URL: https://externals.io/message/77035#77040 · In reply to: #77039

> Hi Matteo,
> 
> BSD does accept it as sem_timedwait, which I could find a reference for
> FreeBSD:
> 
> http://www.freebsd.org/cgi/man.cgi?query=sema&sektion=9

that's part of the FreeBSD Kernel Developer's Manual, not SysV semaphores ;)


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #77041 — guilhermeblanco@gmail.com — 2014-09-02T15:03:43+00:00

URL: https://externals.io/message/77035#77041 · In reply to: #77040

It's also supported by System V using exactly same API.
Some references:

http://fossies.org/dox/glibc-2.19/sem__timedwait_8c_source.html
http://manned.org/sem_timedwait/83baa20c
http://linux.die.net/man/3/sem_timedwait
http://pubs.opengroup.org/onlinepubs/009695399/functions/sem_timedwait.html




> 
> > […]
>
> that's part of the FreeBSD Kernel Developer's Manual, not SysV semaphores
> ;)
>
>
> Cheers
> --
> Matteo Beccati
>
> Development & Consulting - http://www.beccati.com/
>



-- 
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada

---

## #77073 — guilhermeblanco@gmail.com — 2014-09-05T15:38:16+00:00

URL: https://externals.io/message/77035#77073 · In reply to: #77041

After discussing with Matteo, I realized I was referring to POSIX
sempahores and not to System V.

Patch looks ok to me.

Is it possible to have this merged?

Thanks,


On Tue, Sep 2, 2014 at 11:03 AM, guilhermeblanco@gmail.com <
guilhermeblanco@gmail.com> wrote:

> It's also supported by System V using exactly same API.
> Some references:
>
> http://fossies.org/dox/glibc-2.19/sem__timedwait_8c_source.html
> http://manned.org/sem_timedwait/83baa20c
> http://linux.die.net/man/3/sem_timedwait
> http://pubs.opengroup.org/onlinepubs/009695399/functions/sem_timedwait.html
>
>
> 
>
> > […]
>
>
>
> --
> Guilherme Blanco
> MSN: guilhermeblanco@hotmail.com
> GTalk: guilhermeblanco
> Toronto - ON/Canada
>



-- 
Guilherme Blanco
MSN: guilhermeblanco@hotmail.com
GTalk: guilhermeblanco
Toronto - ON/Canada

---

## #77132 — Matteo Beccati — 2014-09-10T07:30:35+00:00

URL: https://externals.io/message/77035#77132 · In reply to: #77073

> After discussing with Matteo, I realized I was referring to POSIX
> sempahores and not to System V.
> 
> Patch looks ok to me.
> 
> Is it possible to have this merged?

I've seen no objections raised, so I committed it to PHP-5.6 and master.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/
