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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: brohreit at gmx dot net
New email:
PHP Version: OS:

 

 [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)

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Thu May 23 00:01:28 2019 UTC