The International Simutrans Forum

Development => Patches & Projects => Incorporated Patches and Solved Bug Reports => Topic started by: jamespetts on March 03, 2009, 12:25:28 am

Title: Multithreading question
Post by: jamespetts on March 03, 2009, 12:25:28 am
I am currently working on code to make convoys wait for a few seconds in certain circumstances. The code is in the convoi_t::vorfahren() method. The only way that I have so far found of making a convoy wait is to change the value of wait_lock inside the step() or sync_step() methods. Changing it inside vorfahren() has no effect. As a consequence of that, I have had to give vorfahren() a return value, and p**** the delay (which is usually 0) back to step() with each individual step.

Clearly, this is inefficient. What I should like to be able to do is set the delay directly from vorfahren(). However, simply changing the wait_lock variable does not work. Some multithreading code is evidently missing from that method that is present in step(). Can anybody suggest what code that I should add to vorfahren() to enable it to set a delay directly, without p****ing a return value?
Title: Re: Multithreading question
Post by: Dwachs on March 03, 2009, 06:31:38 am
The methods convoi_t::warten_bis_weg_frei(..) and convoi_t::suche_neue_route() are called from simvehikel.cc and reset wait_lock. Maybe this kills your approach of setting wait_lock in vorfahren()?

Cant see how your question is related to multithreading  ???
Title: Re: Multithreading question
Post by: prissi on March 03, 2009, 02:36:51 pm
You can't, since simutrans uses cooperative multitasking (you can call INT_CHECK() and the screen will update, but the step and the interaction will be frozen until you continue execution). There is no way out of that without rewriting simutrans nearly from the scratch (and even then I am not sure it work work better).
Title: Re: Multithreading question
Post by: jamespetts on March 03, 2009, 10:17:06 pm
Dwachs,

excellent, thank you, that was the problem! It was just being reset at the end of the method. I have now returned vorfahren() to void, put a temporary variable, "reverse_delay" in that method, initialised to 0, and put "wait_lock = reverse_delay;" instead of "wait_lock = 0" at the end, and it works fine. Thank you for your help.

Edit: Prissi, thank you for explaining what INT_CHECK() does - I had been wondering... :-)