ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 could be wrong, but I think you'd have to look into multi-threading for this.
Thanks for your reply,
if i implement it as thread it will be running always..
but i need a provision to stop this func and start again (like this i may doing many times in my application) .
kindly suggest me how to stop a running thread and restart it again
(syntax)
Unfortunately, I can't help you with threading in C as I've never done it (I've only done threading in Java and naturally there's a different API to be used).
if i implement it as thread it will be running always..
but i need a provision to stop this func and start again (like this i may doing many times in my application) .
Threads can be destroyed, created or whatever at a given momment. You could very well fork a new process, but that usually is unnecessary, wastes resources and makes things more difficult.
You should read something about pthreads. Threads can't be explained in a post. For example:
If you want to be able to stop the background function asynchronously, don't use POSIX threads. POSIX threads don't handle asynchronous interruption well. Instead, use fork(), kill(), and waitpid().
One complication that might arise if you follow my advice is that you'll have to take additional steps if you want the child process and the parent process to share memory (for variables, for example).
Threads can be destroyed, created or whatever at a given momment. You could very well fork a new process, but that usually is unnecessary, wastes resources and makes things more difficult.
You should read something about pthreads. Threads can't be explained in a post. For example:
pthread_exit(test1); // is it correct way of closing a thread and here i getting following warning:
// warning: passing arg 1 of `pthread_exit' makes pointer from integer without a cast
To synchronize the threads you need to use mutual exclusion locks and semaphores (mutexes). A complete discussion of pthreads will also include a discussion of mutexes.
To synchronize the threads you need to use mutual exclusion locks and semaphores (mutexes). A complete discussion of pthreads will also include a discussion of mutexes.
Hi All,
finally i implemented it as timer calling the function at a particular interval of time.
Any difference in performance with timer and thread ?
A timer is fine...for things that should be timed.
If you are depending on a timer to synchronize different execution streams, you probably will get bitten sooner or later - and, more than likely, intermittently.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.