Re: Write my own extenmsion

From: Date: Fri, 20 Jun 2008 14:16:38 +0000
Subject: Re: Write my own extenmsion
References: 1 2 3 4  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-5558@lists.php.net to get a copy of this message
Lars Strojny schrieb: > 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"? > [...] > No Sorry. But when you define this class in both scops, you can exchange objects wiht clmemory. >>> The prefix "cl" stands for? >>> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > [...] > my name ;) >>> 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? > > I use a hashtable to store serialize data. To read this data it will be unserialize. I Know thats not so good, but for my first extension ;) >> 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. > > clmemory used mutex to handle only one access per time! > 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 > I think a mutex class is usefull, to lock/unlock action beetween threads, but the message system can be implement by the user. regards Christian L.

« previous php.pecl.dev (#5558) next »