Re: Write my own extenmsion
| From: | Lars Strojny | Date: | Fri, 20 Jun 2008 12:19:31 +0000 |
| Subject: | Re: Write my own extenmsion | ||
| References: | 1 2 3 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-5557@lists.php.net to get a copy of this message | ||
Hi Christian,
thanks for your answers!
Am Freitag, den 20.06.2008, 13:22 +0200 schrieb Christian Lange:
[...]
> Excample php code or the c extension code?
The C extension (and of course I wouldn't mind a few examples).
[...]
> > So you create a whole new scope for the thread? Say I have class "Foo"
> > included in the parent thread, is the class "Foo" (not the object)
> > available in the child thread?
> >
> >
> Every thread has his own scope, that mean a defined class is only
> visible in the thread scope not in a parent thread scope.
And the other way around. If class "Foo" is defined in the parent scope,
can the child thread create a new instance of "Foo"?
[...]
> > The prefix "cl" stands for?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[...]
> > I would prefer "isRunning". Another hint: PHP has some coding guidelines
> > regarding e.g. names. We prefer camel-case for class names ("FooBar")
> > and lowercase camel-case ("fooBar") for method names.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[...]
> Yes, in every thread is the clmemory synchronous
How is it accessed in a thread? Does the variable "just exist"? Is it a
singleton?
> Thread1:
> $clmemory->abc = "Hallo";
>
> Thread2:
> echo $clmemory->abc;
>
> or
>
> Thread1:
> $clmemory->i = 0;
> while(1) {
> $clmemory->i++;
> }
>
> Thread2:
> while(1) {
> echo $clmemory->i."\r";
> }
While shared memory is very helpful, integrated IPC and a mutex object
would be nice. So that thread could a) send messages to other threads
(not just setting properties, of course, messaging could be emulated
with properties but a more messaging like API might be appropriate) and
b) has a mutex object which can be used to manage access to shared
resources.
What about the following:
Thread 1:
$mgr = MutexManager::getInstance();
$mutex = $mgr->create('foo');
Thread 2:
$mgr = MutexManager::getInstance()
$mutex = $mgr->fetch('foo');
while (!$mutex->aquire());
access_shared_resource();
Messaging:
Thread 1:
$m = ThreadMessenger::getInstance();
$m->send('my message');
Thread 2:
$m = ThreadMessenger::getInstance();
while ($msg = $m->receive()) {
if ($msg == 'my message') {
do_something();
}
}
Please don't get me wrong. I really like having movement in the threads
area. While threads make it easy to blow away your foot, there are some
use cases where they are really helpful. I just think load currently :)
cu, Lars
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc