You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by sa...@c2.org on 1996/05/23 23:05:51 UTC

help with a concurrency locking problem?

	I have a module which uses a shared anonymous mmap memory
segment. It is an array of structures, one entry per user on my site,
with max_bytes and bytes_sent for each user's daily bandwidth limit. 
	I think that I am having a concurrency problem where if two
increments are happening at the same time then only one increment
takes place. (So users who are only paying for say 500MB/day of
traffic end up getting 800MB of traffic or something, because all the
hits don't increment the counter properly.)

	I attempted fixing it by replacing:

  if(orig->bytes_sent > 0)
    {
      /* Do the increment */
      cls->tableptr[orig->finfo.st_uid].bytes_sent += orig->bytes_sent;
    }


	With:

  if(orig->bytes_sent > 0)
    {
      /* Do the increment */

      /* Wait for the lock to free */
      while(cls->tableptr[orig->finfo.st_uid].lock);

      /* Set the lock */
      cls->tableptr[orig->finfo.st_uid].lock = 1;

      /* Do the increment */
      cls->tableptr[orig->finfo.st_uid].bytes_sent += orig->bytes_sent;

      /* Free the lock */
      cls->tableptr[orig->finfo.st_uid].lock = 0;
    }


	Now anyone have any ideas on how I can check to see if:

A) This was a problem in the first place?
B) This fixes the problem?
C) This makes things worse (that scary-looking while statement up there)?


	Any ideas on a better way to do locking? I could use fcntl
locking but that means I need one fd per user, right? (I need
record-level locking, and I have one record per user)

-- 
Sameer Parekh					Voice:   510-601-9777x3
Community ConneXion, Inc.			FAX:     510-601-9734
The Internet Privacy Provider			Dialin:  510-658-6376
http://www.c2.net/ (or login as "guest")		sameer@c2.net