php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55846 (shmop,) compare-and-swap functionality
Submitted: 2011-10-04 16:10 UTC Modified: 2016-10-07 13:02 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: brohreit at gmx dot net Assigned:
Status: Open Package: *Extensibility Functions
PHP Version: 5.3.8 OS: all
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
36 - 3 = ?
Subscribe to this entry?

 
 [2011-10-04 16:10 UTC] 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);
}



Patches

shmop-cas (last revision 2011-10-04 16:11 UTC by brohreit at gmx dot net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-03 18:16 UTC] 14463068 at qq dot com
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?
 [2016-10-07 13:02 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: *Extensibility Functions
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 02 21:01:28 2024 UTC