Subj : Re: Boss Told Me You Can't Use Semaphore, But I Have To Do Something To : comp.programming.threads From : Scott McPhillips [MVP] Date : Tue Jul 12 2005 11:52 am clusardi2k@aol.com wrote: > Hello, > > I have a assignment just thrown onto my desk by my boss who is > condescending at times. I'm lost! Am I missing something? > > Anyway, what is the easiest way to solve the below task. Do I > have alternatives. I'm looking for a detailed description and maybe > code! > > The job is: > > There are multible programs which use the same library routine > which is an interface to what I'll call a service program. > > The problem is that only 1 request at a time can be serviced by > the service program. The service program cannot be changed at all. > > My boss told me to just use somehting such as shared memory > (via memmap) and set a flag in there to 1 when a program wants > service. The various programs are to wait in a loop until that > flag becomes 0 or a time-out occurs. If the flag becomes 0 then > one process will set it to 1 along with setting other parameters > to send to the service program. If a process times-out it will > return without receiving any service. But, if a process received > service the process will set the flag to 0 for the next process. > > The problem is, woun't this lead to programs setting that > shared memory flag to 1 at the same time causing an eventual loss > of service etc. I.E.:They clobber each other. > > The way I see it is the flag described above is a critical > section and must be protected by a mutual exclusion semaphore. > > I don't see anything wrong with using shared memory for sending > parameters to the service routine. > > My boss says I am not allowed to use semaphores due to > unexplained reasons. > > O'kay what should I do? > > Thank you, > Christopher Lusardi > Sounds like Windows? If so look up InterlockedCompareExchange. In one call it can synchronize and change the bool. -- Scott McPhillips [VC++ MVP] .