Sponsored Content
Full Discussion: Atomicity
Top Forums Programming Atomicity Post 50804 by S.P.Prasad on Monday 3rd of May 2004 06:56:38 AM
Old 05-03-2004
First of all I would like to state that the pseudo-code I have written in my initial post needs modification. Instead of writing LOCK () and REL() as two separate functions, it would be only one subroutine LOCK_REL() implementing the pseudo-code.

Quote:
How are the variables shared - using shared memory?
Yes. This concept is already implemented in the project. All I need to is add up the required variables.

Quote:
No, you can also use a single lock for all resources, so that you might get heavy lock contention but still permit multiple processes to operate independently.
I studied the pseudo-code but that's what exactly we do not want. For example there are 10 process. Assume 2 different process would like to implement LOCK on the array and while 3 different process tries to REL the LOCK on the same array. Only one of the process should succeed for a specific array operation.

Further more of the remaining 5, 3 different process are trying to implement LOCK on 3 different arrays and 2 are REL two separate arrays, then they very well should. I mean they should not wait other wise timing would become a major issue i.e. time to process one transaction would increase.

Here's a sample view of what I would like to implement atomically:

Process'xx'1'xxxxx'2'xxxxx'3'xxxx'4'xxxxx'5'xxxxx'6'
Array'xxxx'A'xxxxx'B'xxxxx'C'xxxx'D'xxxxx'E'xxxxx'F'

xxxxxxxx ..... xxxx..... xx..... xxxx..... xxx......xxx.........
xxxxxxxxL(D)xxxxL(D)xxR(D)xxxxL(E)xxxR(F)xxxL(A)
xxxxxxxx ..... xxxx..... xx..... xxxx..... xxx......xxx.........

Where L stands for LOCK and R stands for REL the lock on array passed as arguments and value at array index 1 states whether array is locked ( value 1 ) or unlock ( value 0 ) . Please ignore the x's as I have put it for alignment purpose

I hope that I am clear in my requirement.

Thanks in advance.

Last edited by S.P.Prasad; 05-03-2004 at 09:55 AM..
 
LOCK(2) 							System Calls Manual							   LOCK(2)

NAME
lockinit, lock, canlock, unlock - shared memory spin lock SYNOPSIS
#include <lock.h> void lockinit(void); void lock(Lock *lk); int canlock(Lock *lk); void unlock(Lock *lk); /* Alef only */ adt Lock { void lock(*Lock); void unlock(*Lock); int canlock(*Lock); }; adt QLock { void lock(*Lock); void unlock(*Lock); int canlock(*Lock); }; adt RWlock { void Rlock(*RWlock); void Runlock(*RWlock); void Wlock(*RWlock); void Wunlock(*RWlock); }; adt Ref { int inc(*Ref); int dec(*Ref); int ref(*Ref); }; DESCRIPTION
These routines are used by processes sharing memory to synchronize using spin locks. Lockinit must be called before the first use of the other routines. Lock blocks until the lock has been obtained. Canlock is non-blocking. It tries to obtain a lock and returns a non-zero value if it was successful, 0 otherwise. Unlock releases a lock. Alef Alef locks have similar functionality, but no special initialization is required. The ADT Lock has functions lock, unlock, and canlock, just like locks in C. QLocks have the same interface but are not spin locks; instead if the lock is taken QLock.lock will suspend execu- tion of the calling task until it is released. Although Locks are the more primitive lock, their use is discouraged and even erroneous for most purposes. For example, Locks cannot syn- chronize between tasks in the same proc. Use QLocks instead. RWlocks manage access to a data structure that has distinct readers and writers. RWlock.Rlock grants read access; RWlock.Runlock releases it. RWlock.Wlock grants write access; RWlock.Wunlock releases it. There may be any number of simultaneous readers, but only one writer. Moreover, if write access is granted no one may have read access until write access is released. Refs manage reference counters. Ref.inc increments the counter and returns the old value; Ref.dec decrements the counter and returns the new value. Ref.ref returns the current value. SOURCE
/sys/src/liblock SEE ALSO
rfork in fork(2) LOCK(2)
All times are GMT -4. The time now is 10:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy