Req #55846 [Com]: (shmop,) compare-and-swap functionality
Edit report at https://bugs.php.net/bug.php?id=55846&edit=1
ID: 55846
Comment by: 14463068 at qq dot com
Reported by: brohreit at gmx dot net
Summary: (shmop,) compare-and-swap functionality
Status: Open
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: all
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
hi, the shmop_cas() is very important, really strongly suggest to patch to shmop extension.
e.g. We're building a Neon-Network using share-memory block, when currently access the memory
block, we need a memory-CAS algorithm. and this patch seems works for 32 bit system. would please
consider?
Previous Comments:
------------------------------------------------------------------------
[2011-10-04 16:10:21] brohreit at gmx dot net
Description:
------------
hi,
think it would be a good idea to have some kind of atomic functions in php
otherwise having any kind of shared memory is pointless imo
so the patch adds a shmop-cas function
current version is gcc specific
i could also provide an x86 asm version (in gcc syntax)
that should at least be adaptable to other compilers
tested and working on 32bit linux, php built using gcc 4.5.2
bj
Test script:
---------------
if ($shm = shmop_open(0, 'c', 0640, 4096))
{
$val1 = rand();
$val2 = rand();
echo("random values: $val1, $val2\n");
$wr = shmop_write($shm, pack('V', $val1), 0);
echo("$wr bytes written\n");
$ov = shmop_cas($shm, 0, 0, $val2);
echo("old val = $ov, should be $val1\n");
$tv = shmop_cas($shm, 0, $ov, $val2);
echo("temp = $tv, should still be $val1\n");
$cv = shmop_cas($shm, 0, $ov, $val1);
echo("current val = $cv, should be $val2\n");
$rstr = shmop_read($shm, 0, 4);
$rarr = unpack("Vval", $rstr);
$rval = $rarr['val'];
echo("value read: $rval, should still be $val2\n");
if (! shmop_delete($shm))
echo("delete shm failed\n");
shmop_close($shm);
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55846&edit=1
Thread (2 messages)