Re: Re: PHP as Application Server
| From: | Matijn Woudt | Date: | Wed, 26 Sep 2012 17:18:20 +0000 |
| Subject: | Re: Re: PHP as Application Server | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-319266@lists.php.net to get a copy of this message | ||
On Wed, Sep 26, 2012 at 5:23 PM, Maciej Liżewski
<maciej.lizewski@gmail.com> wrote:
> in Java (for example) you just write class:
> class Counter {
> static private counter = 0;
>
> public void increment() {
> this.counter++;
> }
> }
>
And here's where things go wrong.. You assume ++ is an atomic
operation, but in Java that's not true for static variables (it is for
local, but what does it matter?)
So you might end up with a race condition here where the counter will
only be incremented once when there are two or more threads. You need
a mutex or semaphore to make sure there's only one thread
reading/writing the counter at the same time (though volatile would
work here too probably).
Writing scripts for an application server requires a much deeper
understanding of threads and computer internals,so as a result it
probably increases error rate.
I think Alessandro explained the rest of the downsides pretty clearly.
- Matijn
Ps. Please bottom-post on this mailing list