Linux and Threads
Daniel Beckham
danbeck at mtginfo.com
Wed Dec 15 15:08:19 GMT 1999
Threads are very easy to use. The only problems that arise are when two
threads try to use the same global variable at the same time. You have to
consider use mutexes/sempahores to resolve locking and memory
issues. But, since a simple daemon like you are proposing wouldn't need
to use a shared variable, you don't have to worry about those types of issues.
Threads are much more efficient, cleaner and much easier to code that a
program that forks... you don't have to worry about closing open file
descriptors and you don't waste memory by making a complete copy of the
program... It's also much easier to pass a socket descriptor to a thread
than it is to pass it to a child that has already forked...
My suggestions, only use fork to turn into a daemon or if your program is
under 50 lines of code.
Check the man pages for:
pthread_create, pthread_exit and pthread_join. Those should get you started.
Daniel
At 10:02 AM 12/10/99 -0700, you wrote:
>On Thu, 09 Dec 1999, you wrote:
>Hmm, if your application is not performance critical a would
>not use threads. It's doable the way you mentioned but it's a PITA
>to debug. Especially without a (free) debugger on Linux that
>supports multi-threading correctly.
>Why not write a separate daemon (server) program to perform your tasks
>by using fork() for each complex task and communicates with the GUI
>program through standard UDP. It's simple, it's far easier to debug,
>client and server may reside on different hosts and fast enough for
>many purposes.
More information about the KDevelop
mailing list