Hi,
In messing around a bit further with the http server code, I decided to have a go at making the HTTP server multithreaded. In this case, I wanted the web server to function such that when a HTTP request is received, a new thread is created whose purpose is to handle the HTTP request. In other words, the http_server_serve() function is made a thread, as opposed it being just a function. However, in making the changes, the execution seems to result in the web server hanging, with the HTTP handler thread not executing at all. This seem to be the case because inserting a call to sleep (via the timer connection) in main() resulted in the HTTP handler function executing. I would have thought that as soon as a HTTP request is received, the main thread would block, and from there schedule the HTTP handler thread (I have invoked start() on this thread, by the way). At the moment, it seems that the main thread blocking seems to result in the entire web server hanging.
Any ideas as to what's going on?
Peter
Hello Peter,
On Wed, Apr 28, 2010 at 04:47:00PM +0930, Peter Nguyen wrote:
Any ideas as to what's going on?
From your description, I guess your code is buggy, but you (again) did
not send sources. Maybe someone on the list could help you, if you send the relevant code snippets from your program.
Ciao
Hi,
Attached is the http_srv code under question. I think the source of the problem is when lwip_accept is called again after creating the thread. The HTTP thread does not execute at all when lwip_accept in main() is invoked again. However, when i insert a call to sleep in the infinite loop, the HTTP thread executes. I also suspect I might not have done enough to make the server truly multithreaded.
Peter
Quoting Christian Helmuth <christian.helmuth@...1...>:
Hello Peter,
On Wed, Apr 28, 2010 at 04:47:00PM +0930, Peter Nguyen wrote:
Any ideas as to what's going on?
From your description, I guess your code is buggy, but you (again) did not send sources. Maybe someone on the list could help you, if you send the relevant code snippets from your program.
Ciao
Christian Helmuth Genode Labs
http://www.genode-labs.com/ · http://genode.org/
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
On Wednesday, 28. April 2010 12:02:18 Peter Nguyen wrote:
Hi,
Hi Peter,
Attached is the http_srv code under question. I think the source of the problem is when lwip_accept is called again after creating the thread. The HTTP thread does not execute at all when lwip_accept in main() is invoked again. However, when i insert a call to sleep in the infinite loop, the HTTP thread executes. I also suspect I might not have done enough to make the server truly multithreaded.
Peter
after quickly looking at your code line 167 was eye-catching to me. You create your thread object on the stack within a loop, so every time your loop body is finished the thread gets deconstructed. You should construct the thread using the heap or have a static set of worker threads responding to the requests. Another problem of creating threads on the stack of another one is, that the creator will run out of stack space quickly.
regards Stefan
Quoting Christian Helmuth <christian.helmuth@...1...>:
Hello Peter,
On Wed, Apr 28, 2010 at 04:47:00PM +0930, Peter Nguyen wrote:
Any ideas as to what's going on?
From your description, I guess your code is buggy, but you (again) did not send sources. Maybe someone on the list could help you, if you send the relevant code snippets from your program.
Ciao
Christian Helmuth Genode Labs
http://www.genode-labs.com/ · http://genode.org/
Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
----- _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
Hi Stefan,
Thanks for that. I was wondering though, the hanging does occur immediately after the first request is received ie. the number of threads created is currently irrelevant, given that after only one thread is created, the server hangs.
Peter
Quoting Stefan Kalkowski <stefan.kalkowski@...1...>:
On Wednesday, 28. April 2010 12:02:18 Peter Nguyen wrote:
Hi,
Hi Peter,
Attached is the http_srv code under question. I think the source of the problem is when lwip_accept is called again after creating the thread. The HTTP thread does not execute at all when lwip_accept in main() is invoked again. However, when i insert a call to sleep in the infinite loop, the HTTP thread executes. I also suspect I might not have done enough to make the server truly multithreaded.
Peter
after quickly looking at your code line 167 was eye-catching to me. You create your thread object on the stack within a loop, so every time your loop body is finished the thread gets deconstructed. You should construct the thread using the heap or have a static set of worker threads responding to the requests. Another problem of creating threads on the stack of another one is, that the creator will run out of stack space quickly.
regards Stefan
Quoting Christian Helmuth <christian.helmuth@...1...>:
Hello Peter,
On Wed, Apr 28, 2010 at 04:47:00PM +0930, Peter Nguyen wrote:
Any ideas as to what's going on?
From your description, I guess your code is buggy, but you (again) did not send sources. Maybe someone on the list could help you, if you send the relevant code snippets from your program.
Ciao
Christian Helmuth Genode Labs
http://www.genode-labs.com/ ÷ http://genode.org/
Genode Labs GmbH ÷ Amtsgericht Dresden ÷ HRB 28424 ÷ Sitz
Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
----- _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
-- Stefan Kalkowski Genode Labs Developer http://genode-labs.com
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
Stefan,
My apologies, the change to allocate the thread via the heap actually worked. Turns out i was changing the wrong version of the code i was using.
Peter
Quoting Stefan Kalkowski <stefan.kalkowski@...1...>:
On Wednesday, 28. April 2010 12:02:18 Peter Nguyen wrote:
Hi,
Hi Peter,
Attached is the http_srv code under question. I think the source of the problem is when lwip_accept is called again after creating the thread. The HTTP thread does not execute at all when lwip_accept in main() is invoked again. However, when i insert a call to sleep in the infinite loop, the HTTP thread executes. I also suspect I might not have done enough to make the server truly multithreaded.
Peter
after quickly looking at your code line 167 was eye-catching to me. You create your thread object on the stack within a loop, so every time your loop body is finished the thread gets deconstructed. You should construct the thread using the heap or have a static set of worker threads responding to the requests. Another problem of creating threads on the stack of another one is, that the creator will run out of stack space quickly.
regards Stefan
Quoting Christian Helmuth <christian.helmuth@...1...>:
Hello Peter,
On Wed, Apr 28, 2010 at 04:47:00PM +0930, Peter Nguyen wrote:
Any ideas as to what's going on?
From your description, I guess your code is buggy, but you (again) did not send sources. Maybe someone on the list could help you, if you send the relevant code snippets from your program.
Ciao
Christian Helmuth Genode Labs
http://www.genode-labs.com/ ÷ http://genode.org/
Genode Labs GmbH ÷ Amtsgericht Dresden ÷ HRB 28424 ÷ Sitz
Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth
----- _______________________________________________ Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
-- Stefan Kalkowski Genode Labs Developer http://genode-labs.com
Genode-main mailing list Genode-main@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/genode-main
On Wednesday, 28. April 2010 13:39:16 Peter Nguyen wrote:
Hi Stefan,
Thanks for that. I was wondering though, the hanging does occur immediately after the first request is received
Yes, because right after you've started the new thread, it gets destructed, because the main thread leaves the loop-body-scope and thereby clears away everything (loop-scope locally) initialized on the stack including the thread-object. This programming error is similar to returning local objects from functions.
Please, turn line 167 into:
http_thread *thr = http_thread(client);
and see what happens. Nevertheless, this is no good solution, as you infinitely produce threads without cleaning up.
regards
Just for completeness,
On Wed, Apr 28, 2010 at 02:07:20PM +0200, Stefan Kalkowski wrote:
Please, turn line 167 into:
http_thread *thr = http_thread(client);
^ `---- insert "new" here
Greets