Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2006 Jan : Shared counter across process

www.cryer.info
Managed Newsgroup Archive

Shared counter across process

Subject:Shared counter across process
Posted by:"Adrien Reboisson" (adrien-reboissonatastasedotc..@spacelab.com)
Date:29 Jan 2006 04:21:43

Hi,

I need to use a kind of counter which could be shared across
processes. For instance :

Process A creates the counter and set its value to 0
Process A increment the counter value
Process B opens the counter and read the value
Process A decrement the counter value
...

What kind of IPC object should I use ?

My first thought was to use a semaphore which would be
initialized to 0. To increment the counter value, I would
call ReleaseSemaphore, and to decrement it I would call
WaitForSingleObject... I don't know if this kind of design is
good - furthermore I don't know exactly how to get the value
of my counter (maybe by using the lpPreviousCount parameter in
ReleaseSemaphore ?...).

So if you have ideas about how to implement this... Any hints
appreciated !

Best regards,

A.R.

Replies:

www.cryer.info
Managed Newsgroup Archive