Non-thread safe code means that it can not be shared between threads, but ot does not mean that it can be used in a detached child thread.
The memory usage of threaded applications can be as small as forked applications as threads can (and should be) reused if done properly.
I usally work with queues with threads and detach all child threads right at the beginning. All requests and results get send then to queues. The main thread waits until the results have been received. | [reply] |
Yeah, the memory issue with threads can be bad, and forking is so clean in that respect. The way to get around it though, is to pre-make a set of empty threads right at the top of the script, and reuse them. That way, there is no overlapping useless code in the thread, and reusing them prevents memory gains. You can then load data to process into each thread thru shared variables. Yeah, it's alot of juggling to do, fork is probably better.
| [reply] |