Sign in to follow this  
tomtomtom

Processes synchronization on windows

Recommended Posts

Hello, I need to make a server & client program, which will send the data from multithreaded client to a singlethreaded server using a named pipe (or generally a shared memory i want to make it customizable). The server just stores the incoming data, so at this point i dont know if it should be multithreaded too. At the moment i was thinking how to make a synchronization, is it better to use events or semaphores? My sample plan for now, im using two event objects and a critical section. ReadyForReadEvent is autoset on creation: Client: ------ 1) Wait until ReadyForReadEvent is not set by the server. -> IN CRITICAL SECTION: 2) Sign-off the ReadForReadEvent, send the data through the named pipe 3) Set the RequestReadyEvent -> OUT OF CRITICAL SECTION 4) go to point 1 Server: ------ 1) Wait until RequestReadyEvent is set 2) Sign-off the RequestReadyEvent, read and process the data from the client 3) Set the ReadyForReadEvent again 4) go to point 1 Am i missing something? Is there any better (maybe faster, more reliable) approach to do the same thing? Unsure Thanks, tom

Share this post


Link to post
Share on other sites
It's usually better to use events. Also note that Windows critical sections won't work across process boundaries. You'll have to use named mutexes, semaphors or events to operate across process boundaries.

Share this post


Link to post
Share on other sites
Quote:
Original post by LessBread
It's usually better to use events. Also note that Windows critical sections won't work across process boundaries. You'll have to use named mutexes, semaphors or events to operate across process boundaries.


I know about the critial section, thats why im using it only in client process :)
Regarding the rest of your sentence, have you read this blog entry for example:
http://www.belshe.com/2007/11/20/semaphores-vs-events-showdown/

It appears events are not always a good solution, but it seems the issue mentioned in the blog entry is a bit different then mine. What do you think?

Share this post


Link to post
Share on other sites
Honestly, I haven't had to contend with synchronization in a while so my grasp of the subject is rusty. It might be easier to work out the synch inside one process first and then split it out into two processes. In the meantime, our exchange has bumped your thread back to the top of the list, so hopefully someone with a less oxidized grasp of the topic will respond to your question.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this