From:             benjamin at josefus dot net
Operating system: Ubuntu 9.04, Kernel2.6.27
PHP version:      5.3SVN-2009-07-21 (snap)
PHP Bug Type:     SPL related
Bug description:  spl_object_hash not unique for Objects used in concurrent 
(forked) environment

Description:
------------
I am working on a Task Management (java-like Threads) where each Task 
implements a pcntl_fork(), which works with shared Objects using IPC and
Semaphore to access concurrently and synchronized. 
The Synchronisation should happen by unique Key per Object and SHM Segment
(delivered by spl_object_hash). I am using sem_acquire(), sem_release(),
shm_attach(), shm_release(), shm_[put|get]_var() and so on. 

When providing two concurrent Tasks with the same Object to be shared,
spl_object_hash delivers two different Hashes, when invoked in each Task.

Interestingly, if i call spl_object_hash for the shared Object before it
is assigned to both "Producer" and "Worker" Task, the Hash IS unique, as it
should be!

In short: 
- new Object 
- fork -> spl_object_hash(Object) is NOT unique

- new Object 
- call spl_object_hash(Object) first off 
- fork -> spl_object_hash(Object) IS unique and correct

System Notes:
PHP 5.3.0 (cli) (built: Jul 21 2009 22:19:17)
Configure Command       './configure' '--enable-pcntl' '--enable-shmop'
'--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm'
'--with-apxs2=/usr/bin/apxs2' '--disable-short-tags' '--with-openssl'
'--with-zlib' '--enable-bcmath' '--with-bz2=/bin/bzip2' '--enable-calendar'
'--with-curl' '--with-curlwrappers' '--enable-exif' '--enable-ftp'
'--with-gd' '--with-jpeg-dir=/usr/lib' '--with-png-dir=/usr/lib'
'--with-xpm-dir=/usr/lib' '--with-t1lib' '--enable-gd-native-ttf'
'--enable-gd-jis-conv' '--with-gettext' '--with-imap' '--with-imap-ssl'
'--with-ldap' '--with-ldap-sasl' '--enable-mbstring' '--with-mcrypt'
'--with-mhash' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd'
'--with-pdo-mysql' '--with-pspell' '--with-readline' '--with-snmp'
'--enable-soap' '--enable-sockets' '--without-sqlite'
'--enable-sqlite-utf8' '--with-tidy' '--enable-wddx' '--with-xmlrpc'
'--with-xsl' '--enable-zip' '--with-pear' '--with-kerberos' '--with-pgsql'
'--with-pdo-pgsql' 

Reproduce code:
---------------
$shared = new MySharedObj();
spl_object_hash($shared); //toggle this line to for in/correct result  

/**
 * $shared is referenced member variable in each task
 */
$producer = new ProducerTask($shared); 
$worker = new WorkerTask($shared);      

$producer->start();
$worker->start(); //outputs different Hash for $shared provided by
spl_object_hash


-- 
Edit bug report at http://bugs.php.net/?id=49010&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49010&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49010&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49010&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49010&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49010&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49010&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49010&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49010&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49010&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49010&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49010&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49010&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49010&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49010&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49010&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49010&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49010&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49010&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49010&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49010&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49010&r=mysqlcfg

Reply via email to