Registry Update

  • Thread starter J.K. Baltzersen
  • Start date
J

J.K. Baltzersen

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
 
V

Victor Bazarov

J.K. Baltzersen said:
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
 
H

HeyBub

J.K. Baltzersen said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top