Problem with timely execution of threads...

Hi Guys,

We are having one multi-threaded application.

The scenario is as follows:

                                            --------------------------------- Client 1
                                           |   

APP Server -------------- Client 2
|
---------------------------------- Client 3

App Server is feeding all the clients.

One particular process (within client) has to be run for each minute. Based on the result of the process one value will be displayed on the client.

At starting all the clients have same value (above mentioned).
After starting the clients, the function invocation for each minute is also happening correctly (found by debugging).

The (timed)function is executed using the threads.
The issue is after the function invocation.....in each client....the threads are executing at different times and hence the (display) count on each client is not matching.

Is there any way/method to make sure that threads (in different clients) execute at the same time ?
or
Is there any other alternate way to efficiently handle this kind of scenario?

App Server is one machine and all the Clients are on another machine.

We are using RHEL - 5.4.

Any help would be greatly appreciated.

Thanks,
14341

If you put your ASCII art inside

code tags

it will come out like you were expecting.

Unless you've got enough cores to have one free for each and every individual client, they literally can't execute simultaneously. By necessity, they take turns. Hopefully that doesn't matter to you.

I presume you're making the threads wait with something like usleep() ? Remember that sleep, usleep, etc may wait more or less time than you were expecting -- and that sleeping two minutes won't make you run every 2 minutes, since the rest your code takes a little time to run too. You should check gettimeofday() to see how long you need to rest. You should also give each thread an identical starting number to measure against, so they're all aiming for the same 2-minute mark.

A better way to do this would be for the app server to signal your clients with a mutex, semaphore, cond, or the like every time two minutes, and have the server tell them when they were supposed to have been woken up.