Skip to main content
Topic: Multithreading question (Read 2901 times) previous topic - next topic

Multithreading question

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?
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.

Re: Multithreading question

Reply #1
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  ???
Parsley, sage, rosemary, and maggikraut.

Re: Multithreading question

Reply #2
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).

Re: Multithreading question

Reply #3
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... :-)
Download Simutrans-Extended.

Want to help with development? See here for things to do for coding, and here for information on how to make graphics/objects.

Follow Simutrans-Extended on Facebook.