Registry Update

Discussion in 'C++' started by J.K. Baltzersen, Jan 3, 2008.

  1. Dear all,

    I have a counter in my Windows registry. Is there any way of ensuring
    that it is updated by one process/thread at a time only.

    One way of updating is retrieving the counter, incrementing it, and
    then writing it back. However, when doing it like this and one has a
    process A and B, one risks process A retrieving the counter, then
    being interrupted by process B, which retrieves the counter,
    increments it, and then writing the updated counter to the registry
    before process A again takes over, incrementing the old counter and
    writing it to the registry.

    I am using RegCreateKeyEx, RegQueryValueEx, and RegSetValueEx.

    The result can be that the counter is incremented by 1 only, whereas
    the wanted result is to have it incremented by 2.

    Is there a simple solution to this problem?

    Any help will be greatly appreciated.

    Thank you very much in advance.

    Best regards,
    J.K. Baltzersen
    J.K. Baltzersen, Jan 3, 2008
    #1
    1. Advertising

  2. J.K. Baltzersen wrote:
    > I have a counter in my Windows registry. Is there any way of ensuring
    > that it is updated by one process/thread at a time only.
    >
    > [..]


    This is not a language problem and as such it cannot be solved by means
    of the Standard C++ language or library alone. Please use mechanisms
    available to you in your OS (like an event or a mutex). Also, when
    asking about OS-specific stuff, please refrain from posting to c.l.c++
    since OS-specific questions are off-topic here. Thanks.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 3, 2008
    #2
    1. Advertising

  3. J.K. Baltzersen

    HeyBub Guest

    J.K. Baltzersen wrote:
    > Dear all,
    >
    > I have a counter in my Windows registry. Is there any way of ensuring
    > that it is updated by one process/thread at a time only.
    >
    > One way of updating is retrieving the counter, incrementing it, and
    > then writing it back. However, when doing it like this and one has a
    > process A and B, one risks process A retrieving the counter, then
    > being interrupted by process B, which retrieves the counter,
    > increments it, and then writing the updated counter to the registry
    > before process A again takes over, incrementing the old counter and
    > writing it to the registry.
    >
    > I am using RegCreateKeyEx, RegQueryValueEx, and RegSetValueEx.
    >
    > The result can be that the counter is incremented by 1 only, whereas
    > the wanted result is to have it incremented by 2.
    >
    > Is there a simple solution to this problem?
    >
    > Any help will be greatly appreciated.
    >
    > Thank you very much in advance.
    >


    Find another way. Vista won't let your software bother the registry.

    Put your counter in a file. Read with lock, update the counter, put it back,
    unlock the file.
    HeyBub, Jan 4, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,627
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    748
  3. Leny
    Replies:
    3
    Views:
    16,919
    Daniel
    Feb 1, 2005
  4. Collin Miller
    Replies:
    10
    Views:
    591
    Roger Pack
    Jul 9, 2010
  5. MoshiachNow
    Replies:
    2
    Views:
    116
    Mumia W. (reading news)
    Nov 21, 2006
Loading...

Share This Page