shared memory vs semaphore?

kyle wong
  • kyle wong

    kyle wong - 2003-10-24

    Is it possible to make mmcache works with semaphore instead of / and shared memory?

    As I know, shared memory is not concurrency acces safe, for example,

    $count = mmcache_get(count);
    $count ++;
    mmcache_put(count, $count, 0);

    If 2 process mmcache_get() at the very close time, such that the 2nd process mmcache_get() before the 1st process mmcache_put(), then the cached key "count" will be +1 only but not +2.

    I got this problem when I try to make my lighting fast counter.

    Will semaphore solve this problem? and is it much slower than shared memory?

    • Dmitry Stogov

      Dmitry Stogov - 2003-10-24

      Good problem, I have understend it.

      The only way to solve it - do locking. MMCache doesn't provide locking functions, but you show - they are necessury. I will try to implement functions mmcache_lock() and mmcache_unlock() and they will solve your problem in the following way.

      $count = mmcache_get(count);
      $count ++;
      mmcache_put(count, $count, 0);


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks