Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a simple testing program these days, which has the following structure:
================================================
main() {
...
// create a working thread
iRet = pthread_create(&thread_id, NULL, &ThreadFunc, pti);
...
signal(SIGALRM, sig_alrm);
alarm(1);
//signal handler for SIGALRM
static void sig_alrm(int signo) {
signal(SIGALRM, sig_alrm);
//now only print the current time
// other codes that do real work are commented
alarm(1);
}
// working thread
void* ThreadFunc (void* arg) {
while(1) {
socket();
bind();
connect();
send();
recv(); // *****
close();// close the socket
}
}
================================================
The problem is that the function sig_alrm() is not called in each second as expected. The time between two consecutive calls to sig_alrm() varies, always several seconds. And I find that sig_alrm() is always invoked when recv() is being called. I am wondering whether calling of recv() within a dedicated thread affects alarm(). Someone here told me that since recv() is a time-consuming function compared to other functions in the thread, as a result, it seems that sig_alrm() is always called when recv() is being called.
Does anyone here know what's wrong with my poor program?
What I want to do is creating some threads to do sth while doing a statistical work periodically(precisely) in the main thread. If alarm() is really not safe for doing this, does anyone have a better solution?
Say thanks in advance.
Last edited by zhubaining; 10-26-2006 at 08:38 AM.
There is a programming section that's probably better suited for your question.
Report your post (click the report button) and ask a moderator to move it.
There is a programming section that's probably better suited for your question.
Report your post (click the report button) and ask a moderator to move it.
Thanks for telling me this. In fact, I have seen the "Programming" section before, however, it is under the sub forum "Non-*NIX Forums" whose name may suggest that it is a place for problems regarding other platforms, such as Windows. I failed to find any other more suitable places, so I posted it here. Now I am embarrassed by having not found the "Report" button that you mentioned . As a result, I still don't know how to move my post to the right place. I am new here. Would you please help more?
Last edited by zhubaining; 10-26-2006 at 04:07 AM.
However, I have manually "moved"(modified and pasted) it to "Forums > Non-*NIX Forums > Programming". And after that, I got a reply quickly. It indicates that post must be placed in right place in order to get answers quickly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.