Replacing an Event with a boolean variable.

This is a discussion on Replacing an Event with a boolean variable. within the Windows Programming forums, part of the Platform Specific Boards category; Somebody please correct me if I'm wrong: A manual-reset Event object can be replaced with a plain Boolean variable if ...

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    Replacing an Event with a boolean variable.

    Somebody please correct me if I'm wrong:
    A manual-reset Event object can be replaced with a plain Boolean variable if the event is only set from a single thread, and only checked/reset in a (different) single thread, and the intent is to poll rather than use efficient waiting.

    Are the requirements here too loose/too tight? Or are plain variables just fundamentally unsuitable for thread sync?

    Thanks.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    the intent is to poll rather than use efficient waiting
    poll on the manual reset event? I do not see a reason here...

    simple variable seems to be enogh here...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by vart View Post
    poll on the manual reset event? I do not see a reason here...

    simple variable seems to be enogh here...
    Yes and no.

    First of all, you will have to be careful with how you set the variable and pill the variable. If you don't know what you are doing, the one thread may not realize that the variable has changed.

    Second, if you EVER need to actually WAIT for the other side to finish, then an event is better - because you can tell the OS that you want to wait for it. You can still poll those, by using a timeout of zero and check if the return result is "WAIT_TIMEOUT". This is certainly safer and doesn't have any risks of "messing" up.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C variable
    By webstarsandeep in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 01:26 AM
  2. variable being reset
    By FoodDude in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2005, 12:30 PM
  3. Replacing a Decimal with a letter in a numeric variable.
    By Dobermin in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2003, 12:38 PM
  4. float/double variable storage and precision
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 07-28-2003, 06:23 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 01:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21