Problem with timely execution of threads...


 
Thread Tools Search this Thread
Top Forums Programming Problem with timely execution of threads...
# 1  
Old 01-05-2012
MySQL 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

Last edited by 14341; 01-05-2012 at 10:51 PM.. Reason: Format is not proper
# 2  
Old 01-06-2012
If you put your ASCII art inside
Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help needed: script for timely average from log file

Please repost your query: Help needed: script for timely average from log file - Thank you. (0 Replies)
Discussion started by: mkfs
0 Replies

2. Shell Programming and Scripting

Execution problem

Hi, I have been trying to run a simple script CONFIG_FILE="/jay/check" . . . for i in `cat $CONFIG_FILE` do loc=`echo $i | cut -d "|" -f2` var=$(find $loc -mtime -1|wc -l) if then echo $loc has files older than 1 day fi done . . . (2 Replies)
Discussion started by: jayii
2 Replies

3. Shell Programming and Scripting

Execution problem

hi all, when i tried executing the script by giving following command $ sh test.sh <parameter> it shows the following output: <none> status code=0 Previously it was working fine.But now its showing this output. (1 Reply)
Discussion started by: sanjay mn
1 Replies

4. UNIX for Dummies Questions & Answers

execution problem

HI I am trying to check the status of port using command /code: netstat -an | grep port /Output: *.2009 *.* 0 0 65535 0 LISTEN what i am trying to do is i want to grep only status Wether the port is established/listen if so show ok else... (1 Reply)
Discussion started by: esumiba
1 Replies

5. UNIX for Dummies Questions & Answers

execution problem

Hi I am automating my few commands out of which one command is tail -f running.logs when i run this command it does not automatically exit and show prompt (#) what would i do so that it will exit out automatically after few seconds and move to the next command without using ... (4 Replies)
Discussion started by: esumiba
4 Replies

6. UNIX for Dummies Questions & Answers

execution problem

Hi i have a file in which there are three fields code: 919804199233 404911130003916 357266044991350F and now i want to add two more fields i.e. code: 919804199233 404911130003916 357266044991350F ms 123 how can i do it using command line and if have a file of 100... (8 Replies)
Discussion started by: esumiba
8 Replies

7. UNIX for Dummies Questions & Answers

execution problem

Hi i am using expect module and trying to login using following code. ssh 127.0.0.1 expect "word:" send "$password \n" kindly let me know the login script using expect module (1 Reply)
Discussion started by: esumiba
1 Replies

8. Programming

problem with threads in C

I have problem that if I create for example 100 threads program work correctly but if I define more threads for example 1000 // if I change static int NUM_E from 100 to 1000 than program stop about 350 threads and doesn't continue where should be problem please? #include <pthread.h>... (4 Replies)
Discussion started by: Sevco777
4 Replies

9. HP-UX

%Internal DCE Threads problem (version CMA BL10+)

Hi, I have a module by the name gateway, and it core dumps and gives a cma_dump.log file which says: %Internal DCE Threads problem (version CMA BL10+), terminating execution. % Reason: dispatch: no available VP (uniprocessor) The current thread is 3 (address 0x40107c40) DECthreads... (0 Replies)
Discussion started by: vanz
0 Replies

10. Shell Programming and Scripting

Perl v5.8.5 Threads Problem

Hi Unix gurus, I am facing a threading problem in Perl. I have a worker thread in perl in which I am calling a shell script. The shell script echo's output to the Standard Output from time to time as it progresses. In the worker thread, I am unable to display the echo statement of shell... (1 Reply)
Discussion started by: som.nitk
1 Replies
Login or Register to Ask a Question