wesnoth-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-dev] Network operations and threading


From: David White
Subject: [Wesnoth-dev] Network operations and threading
Date: Mon, 30 May 2005 21:29:57 -0500
User-agent: Mozilla Thunderbird 0.8 (Windows/20040913)

One of the more nasty issues that I think we should resolve before 1.0 is described in this bug report: https://savannah.nongnu.org/bugs/index.php?func=detailitem&item_id=12614

The basic problem is that when a network connection is attempted, Wesnoth makes some blocking network calls, and waits for them to complete. In the case of a problem, Wesnoth may remain blocking for a long period of time, which will appear to the user as Wesnoth simply freezing.

I think this is very poor behavior and needs to be rectified, but I don't know enough about threading to confidently say what the best solution is.

My thought is that we should create some kind of interface for an 'asynchronous operation'. In pseudo-code, I mean something like this:

execute_asynchronous_operation(asynchronous_operation& op, waiter& waiter_obj)
{
   start thread which executes operation defined by 'op'
while(waiter_obj is still willing to wait for the operation to complete) {
      wait for 'op' to finish for 50ms, and if it has, return
   }

   terminate the operation and return
}

'waiter_obj' would perform some kind of operation to see if it's willing to wait -- such as display a dialog box to the user.

I think this would work okay...the main question I have is of how to terminate the operation. I'm not sure if it's okay to generally go around killing threads when they are in a blocking call such as resolving a hostname, or sending data over the network. Does anyone know? Alternatively I guess we could leave the thread running and have it joined() on program exit, hoping that it is done whatever it was doing by then.

Any thoughts or comments from those who know more about this than me would be appreciated. :)

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]