Click to See Complete Forum and Search --> : IPC via Semaphore


Guidosoft
March 21st, 2006, 11:32 AM
I just recently learned about this interpocess counter called a semaphore and it got me to wondering. Perhaps you could use this to send messages to windowless processes.

Think about it. You have 2 semaphores.

1. The pulse semaphore.
2. The flag semaphore.

Now the flag semaphore is set to 0. Its max is 1.
The pulse sephamore is set to 0 and has a max of 256.
1 is 0, 2 is 1, so on.

Now, when the flag sephamore is set to 1(which you know by WaitForObject), you release the pulse sephamore to the byte number you want.

Then the one that is reading the data, will keep Waiting for the pulse object until it gets WAIT_TIMEOUT. It loops however many it recieved and counts. The count -1 is the byte number.

It writes this to a buffer, then relealses flag sephamore and repeats the process. This is how it recieves bytes.

With a few extra imhancements you can devise a fully fledged interprocess communication system.

What do you guys think of this idea? Do you think it is possible to do it in this way?

wildfrog
March 21st, 2006, 02:03 PM
What do you guys think of this idea? Do you think it is possible to do it in this way?It is possible. But, it is ugly.

If you need to send data between two (or more) processes I would suggest using Pipes, Named Pipes, Sockets or Shared memory.

- petter

golanshahar
March 21st, 2006, 02:11 PM
In addition to wildfrog post, you can also use ::SendMessage() with WM_COPYDATA ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/datacopy/datacopyreference/datacopymessages/wm_copydata.asp ) ;)

Cheers