LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Obtain Semaphore Reference SIZE greater than one - Example Request

hi everybody!

 

so i started using semaphores quite a bit recently,

and was trying to find a use-case that needed more than one party to acquire the lock.

 

i couldn't think of one.

my thought is, that if it is only a READ-access, then i don't acquire a lock and jsut read (if i don't care for data integrity),

but WRITE-accesses should always have the lock, so no dirty updates can occur.

 

i'd appreciate it, if you could think of a sensible example.

 

greetings


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 1 of 7
(3,474 Views)

If you only need 1 party to acquire the lock, then you do not need a lock.  In your example, I would just use an Action Engine and let the non-reentrant VI boundary do the locking for me.

 

The only real legitimate use of a Semaphore I have ran into was when dealing with an instrument that had a lot of different capabilities (DIO, switches, DMM).  I had a different module for each of those capabilities and used the Semaphore to keep each module from stepping on top of the other.  Not long after that I learned that VISA has a locking mechanism I could have used instead of the Semaphore that would have made it a little simpler.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(3,459 Views)

sorry my writing seems confusing 😞

 

of course i would have several parties interested in acquiring the lock to one variable,

but why would i want to have (eg) two that hold the lock at the same time?


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 3 of 7
(3,455 Views)

@jwscs wrote:

but why would i want to have (eg) two that hold the lock at the same time?


The point of a Semaphore is to only allow 1 thing access a resource at a time.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 7
(3,448 Views)

thats exactly my point, but why does the "Obtain Semaphore Reference" allow to set a "size">1

http://zone.ni.com/reference/en-XX/help/371361L-01/glang/obtain_sem_ref/

 

or is it that i misunderstand the documentation for "size"?


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 5 of 7
(3,436 Views)

i thought about a (not sensible use-case):

 

it would be possible to control execution flow, several tasks can work while another (one) waits until the locks are released

 

but it doesn't make mcuh sense (yet) for me regarding the dirty-read/write problem,

 


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
0 Kudos
Message 6 of 7
(3,430 Views)

@crossrulz wrote:

@jwscs wrote:

but why would i want to have (eg) two that hold the lock at the same time?


The point of a Semaphore is to only allow 1 thing access a resource at a time.


Not 1 thing. N things.

 

I don't have a particular use case in mind (it's been quite a few years since I wrote code with semaphores), but I can certainly imagine cases where you say "I want at most N process to access a particular resource to minimize resource contention".


___________________
Try to take over the world!
0 Kudos
Message 7 of 7
(3,374 Views)