------------------------------------------------------------------------------- Multiple Thread Discussion The following was saved from the Crossfire mailing list.. ---- No offense intended, but I have been writing multi-threaded C code for at least four years now and I think it is easier than writing single threaded applications. As long as you very clearly keep various logic within a thread and pass events between threads (as compared to keeping the event within a thread and possibly forcing yourself to grab a series of locks before doing the intended action) then it is relatively easy. That is where people get themselves screwed up by having every subroutine callable from every thread. The right way to do it is to have threads that do specific things and so if another thread wants that action done then it pass the event to another thread and signals it to act. And events passed are not required to be acted upon immediately or risk deadlock, but put upon a queue. People get themselves into trouble by thinking about machine time delays as compared to human time. Maybe threading will make something happen after something else that CPU time could argue event is now out of sequence, but which event really should have occurred first is dependent on many otherside factors (net delays and so on) and so application (ie CF) is okay just dealing with events as they come up and not worrying much about microsecond latency and timing issues. While I have not worked on CF recently, I have worked on it enough in the past to know that a map is pretty well isolated from all other events on other maps. Moving an object between maps would require synchronization as would communications between members of a party. But that is it. Player being a thread would mostly just be some checks to see if current event can be handled locally within the thread or if event needs to be passed to map thread. Fork() sucks because it is then so much harder to pass info between processes. Lastly, I may be nuts, but apparently I have been so for quite a while now and it is easier than the alternatives. I am not saying that multi-threading CF is merely a weekend project do be done between watching sporting events, but it is something that could reasonably be done in 200 hours of programming effort. PS. The multi-threaded stuff I write is not merely some stuff of personal interest, but to be up for months on end and servicing millions of users between restarts. So any threading bugs would likely be seen and hence I am talking about something I am knowledgeable. I am not claiming to be some god of threaded applications, but I think by giving up theoretical optimizations and by keeping it simple which could even be called stupid then it'll work well. The performance gains are not in the microsecond range of being able to handle this or that slightly faster, but in the occasional larger chunk of time where being single threaded made quickly responding to an event too difficult to fully implement. Scott Wedel -------------------------------------------------------------------------------