Jump to content

What is the perfect use for the Semaphore?


Recommended Posts

QUOTE (Jim Kring @ Nov 17 2008, 10:52 AM)

I think your 'no race condition' code still has a race condition. What is there to prevent the semaphone from being destroyed before the lower path is executed? I think you need to wire the semaphore or the error out of the release call in the lower loop to the border of the sequence with the destroy in it to 'ensure' that the destroy cannot happen untill all code paths needing the semaphone are complete.

Also, the use of sequence frames and semaphores could be eliminated by instead protecting the data in a single element queue instead. This is a cleaner way to solve the problem and better coding practice, but would not demonstrate the use of the semaphone.

Link to comment

QUOTE (jlokanis @ Nov 18 2008, 11:45 AM)

Great point -- yes, there is a race condition that could cause the destroy to happen before the bottom modification occurs.

I originally (when I created the example) had something like the one, below, but I removed the error handling to emphasize the use of semaphores.

post-17-1227048314.png?width=400

You're right that (short of using error chaining) wiring the bottom semaphore reference to the destructor's sequence structure (as shown below) is a good fix.

post-17-1227048523.png?width=400

QUOTE (jlokanis @ Nov 18 2008, 11:45 AM)

Also, the use of sequence frames and semaphores could be eliminated by instead protecting the data in a single element queue instead. This is a cleaner way to solve the problem and better coding practice, but would not demonstrate the use of the semaphone.

Yes, you could definitely use a single element queue. You could also use a functional global variable. Along those lines, Appendix D of LabVIEW for Everyone (where I pulled this example from) provides a historical overview of the different mechanisms for doing by (non-native) object-oriented programming in LabVIEW (and shows the natural progression of technologies and features). However, it does not touch the single-element queue or other more advanced implementations of by reference objects.

Thanks,

-Jim

Link to comment

QUOTE (Jim Kring @ Nov 18 2008, 02:21 AM)

When did this turn into a negotiation? :unsure:

Don't take my stab at humor the wrong way. I was trying to point out how absurd NOT owning that book is, for the price Amazon is charging ($53 with free shipping). I actually have your older version. It'll be on eBay when my Ed.3 arrives, complete with coffee and beer stains! :beer:

Link to comment

QUOTE (BrokenArrow @ Nov 19 2008, 06:10 AM)

Don't take my stab at humor the wrong way. I was trying to point out how absurd NOT owning that book is, for the price Amazon is charging ($53 with free shipping). I actually have your older version. It'll be on eBay when my Ed.3 arrives, complete with coffee and beer stains! :beer:

No worries :)

I hope you enjoy the 3rd edition. Feel free to bring it to NIWeek and I'll happily sign it -- but that might make it worth less on eBay than the coffee and beer stains ;)

Cheers,

-Jim

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.