[PHP-DEV] request for thread safety advice

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Re: [PHP-DEV] request for thread safety advice

    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
    >
    >On Mon, 20 Oct 2003, 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
    > > [url]http://www.unix.org/version2/whatsnew/threads.html[/url]
    > > [url]http://www.unix.org/version2/whatsnew/threadsref.html[/url]
    > > 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 :)
    > >
    > >
    > >
    >
    >--
    >PHP Internals - PHP Runtime Development Mailing List
    >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    -----
    Uwe Schindler
    [email]thetaphi@php.net[/email] - [url]http://www.php.net[/url]
    NSAPI SAPI developer
    Erlangen, Germany

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Uwe Schindler Guest

  2. Similar Questions and Discussions

    1. Thread safety/synchronization?
      Flex/AS doesn't appear to have any overt synchronization mechanism, is it handled under the covers (ie is every method synchronized?) or is it user...
    2. OT: Blue Bulb Hazard Warning, & Safety Advice Request
      This just happened this evening and I wanted to post a warning right away: Many of the pix that I shoot have some, often unavoidable, component of...
    3. apartmant thread safety
      I'm rather confused about this whole threading business of IIS, ASP and COM components. We have an apartment threaded component with a function...
    4. Trying to figure out thread safety
      (Having been told of a solution to one problem (File::CREAT was indeed what was needed), I'll now go off on something entirely different.) I've...
    5. Thread safety of vm_copy
      I tried looking around for explicit documentation on this but to no avail, perhaps it is too basic. On Mac OS X the Mach function vm_copy has a...
  3. #2

    Default Re: [PHP-DEV] request for thread safety advice

    The question is if this is always enough. Say for example hypothetically
    that the GD library saves the state of the currently being manipulated
    graphic, it won't be enough to mutex its calls because there's some saved
    state in between the calls.
    I'm not sure there's a general way to deal with it. Sure you could have
    some general code for a mutex but I don't think that'll solve all of the
    problems.

    Andi

    At 02:06 AM 10/21/2003 +0200, Uwe Schindler wrote:
    >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
    >>
    >>On Mon, 20 Oct 2003, 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
    >> > [url]http://www.unix.org/version2/whatsnew/threads.html[/url]
    >> > [url]http://www.unix.org/version2/whatsnew/threadsref.html[/url]
    >> > 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 :)
    >> >
    >> >
    >> >
    >>
    >>--
    >>PHP Internals - PHP Runtime Development Mailing List
    >>To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >-----
    >Uwe Schindler
    >thetaphi@php.net - [url]http://www.php.net[/url]
    >NSAPI SAPI developer
    >Erlangen, Germany
    >
    >--
    >PHP Internals - PHP Runtime Development Mailing List
    >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Andi Gutmans Guest

  4. #3

    Default Re: [PHP-DEV] request for thread safety advice

    True, I should have mentioned that the mutex might have to span an entire
    sequence of calls from open to close or something to that effect.

    In the specific case of GD, it wouldn't actually be hard to make it
    threadsafe. Shane did it before to GD1 and it should probably be done
    again for our bundled version of GD2.

    -Rasmus

    On Tue, 21 Oct 2003, Andi Gutmans wrote:
    > The question is if this is always enough. Say for example hypothetically
    > that the GD library saves the state of the currently being manipulated
    > graphic, it won't be enough to mutex its calls because there's some saved
    > state in between the calls.
    > I'm not sure there's a general way to deal with it. Sure you could have
    > some general code for a mutex but I don't think that'll solve all of the
    > problems.
    >
    > Andi
    >
    > At 02:06 AM 10/21/2003 +0200, Uwe Schindler wrote:
    > >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
    > >>
    > >>On Mon, 20 Oct 2003, 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
    > >> > [url]http://www.unix.org/version2/whatsnew/threads.html[/url]
    > >> > [url]http://www.unix.org/version2/whatsnew/threadsref.html[/url]
    > >> > 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 :)
    > >> >
    > >> >
    > >> >
    > >>
    > >>--
    > >>PHP Internals - PHP Runtime Development Mailing List
    > >>To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    > >
    > >-----
    > >Uwe Schindler
    > >thetaphi@php.net - [url]http://www.php.net[/url]
    > >NSAPI SAPI developer
    > >Erlangen, Germany
    > >
    > >--
    > >PHP Internals - PHP Runtime Development Mailing List
    > >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Rasmus Lerdorf Guest

  5. #4

    Default Re: [PHP-DEV] request for thread safety advice

    On Mon, 20 Oct 2003 17:35:30 -0700 (PDT)
    Rasmus Lerdorf <rasmus@lerdorf.com> wrote:
    > True, I should have mentioned that the mutex might have to span an
    > entire sequence of calls from open to close or something to that
    > effect.
    >
    > In the specific case of GD, it wouldn't actually be hard to make it
    > threadsafe. Shane did it before to GD1 and it should probably be done
    >
    > again for our bundled version of GD2.
    While working on my new gfx lib, I use these macros especially for FT2
    and its cache and for the vectors graphics.

    I did not deeply test and analyze external libs like png, tiff, and
    others to see if they are really TS, but the most widely used seem to
    be TS as there is not global static data. But I'm really not a thread
    expert :-/

    I'm interested in every issues you have got using GD2 (bundled) and how
    you think to solve them (or how have you already solved them).

    pierre

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Pierre-Alain Joye Guest

  6. #5

    Default Re: [PHP-DEV] request for thread safety advice

    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
    > [url]http://www.unix.org/version2/whatsnew/threads.html[/url]
    > [url]http://www.unix.org/version2/whatsnew/threadsref.html[/url]
    > 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 [url]http://www.doal.co.il:81/free/?c=both[/url]

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    netcat Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139