Re: Memory leak in unix/pthread.fs
paul.ortais-WGBUbHxT2D9Wk0Htik3J/[email protected] Sat, 12 Nov 2022 19:11:19 +0100
| Newsgroups | gmane.comp.lang.forth.gforth |
|---|---|
| Message-ID | <[email protected]> |
Great contribution, thank you very much ZP Le 2022-11-08 15:38, nature a écrit : > Hi, > > I am working on a web server written in pure Forth and I am using > gforth > as the implementation I develop on. Serving multiple requests without > blocking requires me to venture into the realm of multi-threading and > gforth's experimental support for pthread has been a blessing. It may > be good for me to mention that I work on UNIX (OpenBSD). > > Now instead of doing like in cilk.fs and spawning a few workers and > offloading requests to them, I prefer to create a separate thread each > time a request comes and this led me to notice that my server wasn't > able to serve more than ~3k requests before hanging and also the memory > usage of my process increased a lot with each new request comming in. > I > then proceeded to hunt down memory leaks due to the S" S\" and S+ words > with minimal impact. That is what lead me to realize that creating new > threads with the PASS word was creating non-detached thread which never > freed the memory once the thread exited. > > I am attaching a patch for unix/pthread.fs which fixed the big memory > leak for me, my server is no able to server well above 3k requests > without hanging/crashing (I tested 10 without any issues). > > Also optionally I am attaching another patch for cilk.fs just to > correctly get the number of cores on OpenBSD. > > Thank you for the great work on gforth, I can't wait for the official > 1.0 to release so that OpenBSD ports won't be stuck with 0.7.3 forever! > :D > > Cheers,