Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^3: When to use forks, when to use threads ...?

by wojtyk (Friar)
on Sep 04, 2008 at 18:21 UTC ( #709086=note: print w/replies, xml ) Need Help??

in reply to Re^2: When to use forks, when to use threads ...?
in thread When to use forks, when to use threads ...?

It is possible to deadlock two separate processes that communicate with one another if the protocol between them is not well designed
Fair enough, but still seems like a nitpick (in that it is possible, but not probable - whereas in the case of programming threaded apps, it's a common occurrence). Also in the case of separate processes, it's much easier to recognize & debug.
The "fewer memory leaks" claim isn't necessarily true either
This one I stand by (in the statistical average case), particularly as the software grows more complex. As you mentioned, process termination is a natural "reset switch" that does wonders in keeping leaks down. But there's a whole host of other reasons that make memory leaks more common in threaded apps:

- Harder to recognize and pinpoint (and thus fix...), since "memory usage" reported will be a macro-level observation instead of a process-isolated observation
- More frequent use of resource locks (ie semaphores), reference counting, and shared resources in threaded apps, making it easier to leave resources in a limbo state
- Maybe a redundant point, but "increased coding complexity" when using threads increases the possibility of a coding error

As with all things involving coding, _any_ piece of code could be done "right" with no memory leaks, but I believe it's much easier to both introduce leaks AND harder to pinpoint and fix them in threaded apps vs standalone processes.

  • Comment on Re^3: When to use forks, when to use threads ...?

Replies are listed 'Best First'.
Re^4: When to use forks, when to use threads ...?
by mr_mischief (Monsignor) on Sep 04, 2008 at 19:23 UTC
    I agree in general, although I don't have enough data to analyze anything statistically. I'm just pointing out that "less likely" is not the same as "cannot happen" and that "probably fewer" doesn't mean "definitely fewer". Your earlier post seemed absolute. The same programmer writing the same project in the two different methods seems likely to experience fewer leak and deadlock problems with processes than with threads. That's not necessarily the case, though. "Necessarily" is the key word.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://709086]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2018-04-19 16:18 GMT
Find Nodes?
    Voting Booth?