|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Thu Jul 15, 2010 12:23 am
[3XXB] Events and threads |
As I understand it, events run on separate threads which is fine in most cases, however sometimes this can cause problems.
Take the case of in-room (or in-zone) scripts, they don't become visible until the onRoomEnter (or onZoneEnter) fires. By the time the thread makes these scripting objects available, the room in which the script is relevant has already been traversed and the result is out of sync with the mapper. This is especially true in the case when an alias is used as room exit.
My question is: Is there a way to force the event to run on the main thread (in this case, the thread talking to the MUD) to insure synchronization?
If one just places the script in a folder which is already enabled prior to entering the room (i.e. the script is event-independent), then there is no problem. I would like to take advantage of the event mechanism and still get the same results. |
|
_________________ Sic itur ad astra. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Jul 15, 2010 12:33 am |
Actually this is incorrect. Even if CMUD internally uses threads, they are not *background* threads. Events still interrupt other script processing and do not run simultaneously in the background. When the mapper "raises" the onRoomEnter event, any scripts associated with that event should be run and CMUD waits until they are finished before continuing. At least, this is how I think it is supposed to work. If you can confirm that event handlers are running in the background at the same time as other scripts, then post some test code.
|
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Thu Jul 15, 2010 12:53 am |
I have no proof that they do run in the background. However, that would explain why the exit aliases don't get executed in time when they become visible during the onRoomEnter event, for instance. I am assuming, of course, that this is what enables the room folder. If the scripts are kept in a folder which is already enabled, they execute. If the scripts are put in the Roomxxxx folder (which is disabled by default) they execute too late.
|
|
_________________ Sic itur ad astra. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Jul 15, 2010 2:24 pm |
My own tests, quite a ways back, seemed to show that events are definitely not backgrounded. I don't have those tests lieing around, but maybe I can test later. I believe the problem is that the onRoomEnter event is raised too early by the mapper. In fact, I believe this was reported long ago.
|
|
|
|
|
|