Your plan is workable, but boolean vairables are not commonly used when it
comes to syncing threads.
This is where the semaphore(include pthread and semaphore.h, link with
-lpthread) comes into play. When game_loop_unix finishes a loop, make it
update a global data structure with all the data that the webserver needs to
know, then posts a semaphore, unblocking the webserver loop.
On Thursday 07 August 2003 11:42, Dale Kingston wrote:
> Ok I've been wanting to do this for sometimes but I haven't known how to do
> it. And then with the resent mention of threads I figured this might be how
> I could do it. I have a web server attached with the mud. You can see a lot
> with it, skills, spells, Pcstores, can login write notes, and see who's
> online. Well for sometimes I've been wanting this in it's own process or
> thread. So I read some of the tutorials on how to use threads and I'm still
> a little confused at how I could use 1 thread to run the web server rather
> then a thread per request. Here's my idea tell me if I'm total wrong with
> my thinking.
>
>
>
> In game_loop_unix I have it called handle_webserver, and so that runs with
> each game loop which I would still like to preserver, so what I was
> thinking. Is make the thread for the handle_webserver at the end of our
> init_web server. Then make a two global bools for when it's to run it's
> update, and then like a web_down bool. Then do like game loop unix and have
> the handle do a while (!web_down) And then inside that have the other bool
> be like if (!update_web){continue;) then in the game loop unix have it flag
> that bool true each time it runs throung. And at the end of the handle_web
> have it flag it false.
>
>
>
> Would that work how I'm thinking where it would keep it in it's own thread.
> And that thread would process all the web server information? Or am I like
> total screwed up on my logic of how to have it work?