# request for thread safety advice

- Thread: https://externals.io/message/4897
- Original archive: https://news-web.php.net/php.internals/4897
- Started by netcat on 2003-10-20T19:18:42+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #4897 — netcat — 2003-10-20T19:18:42+00:00

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

Hi, internals.

Please send me (post here i mean) a few links about
1. thread safety in general
2. thread saftey in php
3. I'm doing wrapper for librep wich is not thread
safe (so mailing archives say). Do I need to know
something special ?


After doing some googling i found thise for #1
http://www.unix.org/version2/whatsnew/threads.html
http://www.unix.org/version2/whatsnew/threadsref.html
is that a good reading ?

any better suggestions for google requests than thise :
c thread safety -mail -archive -lists
c thread safety tutor
?

I couldn't find anything for #2 but it's not less
important than #1 :)


-- 
NetCat



------------------------------------------------------
SPAM-Free 10mb Free email + Antivirus + POP3 + more...
Get it at http://www.doal.co.il:81/free/?c=all-spam

---

## #4898 — Rasmus Lerdorf — 2003-10-20T22:10:44+00:00

URL: https://externals.io/message/4897#4898 · In reply to: #4897

If the library you are wrapping is not threadsafe, one approach is to 
simply not worry about it and just mark your extension as not being safe 
to use in a threaded environment.  The majority of people use PHP in a 
non-threaded environment anyway.

If you want to be nice to the folks who do use PHP in a threaded 
environment, you can look into adding a semaphore lock around the calls 
into the code that is not threadsafe.  Such a semaphore lock makes sure 
that only 1 thread at a time can enter the code.  Other threads sit around 
and wait until it is their turn.  

-Rasmus



> Hi, internals.
> 
> Please send me (post here i mean) a few links about
> 1. thread safety in general
> 2. thread saftey in php
> 3. I'm doing wrapper for librep wich is not thread
> safe (so mailing archives say). Do I need to know
> something special ?
> 
> 
> After doing some googling i found thise for #1
> http://www.unix.org/version2/whatsnew/threads.html
> http://www.unix.org/version2/whatsnew/threadsref.html
> is that a good reading ?
> 
> any better suggestions for google requests than thise :
> c thread safety -mail -archive -lists
> c thread safety tutor
> ?
> 
> I couldn't find anything for #2 but it's not less
> important than #1 :)

---

## #4899 — Uwe Schindler — 2003-10-21T00:06:41+00:00

URL: https://externals.io/message/4897#4899 · In reply to: #4898

nice for that would be some macros (somewhere in zend????) which help in 
the following way (the ext_skel should generate the code, too):

a) define a global library identifier (for all blocks that should not run 
at the same time)
         zend_create_mutex(identifier)

b) use some code like:
         zend_start_synchronized(identifier) {
                 ...
                 ...
         } zend_end_synchronized(identifier);

(Same construct like zend_try). Without ZTS this macros should be empty...

As I am the developer of the NSAPI SAPI (which runs only with ZTS) I would 
like to have a GD extension where alle PHP_FUNCTIONs exported from there 
should have such Java-like "synchronized" blocks.

Uwe

At 00:10 21.10.2003, you wrote:
>If the library you are wrapping is not threadsafe, one approach is to
>simply not worry about it and just mark your extension as not being safe
>to use in a threaded environment.  The majority of people use PHP in a
>non-threaded environment anyway.
>
>If you want to be nice to the folks who do use PHP in a threaded
>environment, you can look into adding a semaphore lock around the calls
>into the code that is not threadsafe.  Such a semaphore lock makes sure
>that only 1 thread at a time can enter the code.  Other threads sit around
>and wait until it is their turn.
>
>-Rasmus
>
>
>
> > […]
>
>--
>
>

-----
Uwe Schindler
thetaphi@php.net - http://www.php.net
NSAPI SAPI developer
Erlangen, Germany

---

## #4911 — netcat — 2003-10-22T08:20:30+00:00

URL: https://externals.io/message/4897#4911 · In reply to: #4897

netcat wrote:

> Hi, internals.
>
> Please send me (post here i mean) a few links about
> 1. thread safety in general
> 2. thread saftey in php
> 3. I'm doing wrapper for librep wich is not thread
> safe (so mailing archives say). Do I need to know
> something special ?
>
>
> After doing some googling i found thise for #1
> http://www.unix.org/version2/whatsnew/threads.html
> http://www.unix.org/version2/whatsnew/threadsref.html
> is that a good reading ?
>
> any better suggestions for google requests than thise :
> c thread safety -mail -archive -lists
> c thread safety tutor
> ?
>
> I couldn't find anything for #2 but it's not less
> important than #1 :)
>
>
Thanks for all the replies.
I will probably have more questions when i'll have
the time to continue working on the project.

-- 
NetCat



--------------------------------------------------------
FREE 10MB email + Antivirus + AntiSpam + POP3 + more....
Get it at http://www.doal.co.il:81/free/?c=both
