[Pogamut-list] Threads

jakub.gemrot pogamut-forum at diana.ms.mff.cuni.cz
Wed Feb 20 08:34:59 CET 2013


Re: Threads

Author: jakub.gemrot

How it works:

Each bot in PogamutUT2004 has two threads. 
1) GB2004 consumer
-- constantly reads messages from the GB2004 connection
2) Logic
-- thread that is running logic() method of the UT2004BotModuleController

However, these two threads may never collide, their work is controlled by the WorldView as the data flow looks like this
GB2004 consumer | WorldView | Logic

Once the Logic thread wants to execute logic(), it locks the WorldView, which prevents any modifications to the data while the Logic thread is running, that is any new messages from GB2004 consumer is buffered and their processing is postponed, till the Logic thread finishes and unlocks the WorldView again. From the bot-programmer, it seems like there is only a single thread in there.

But, if you are going to run 2+ bots in the same JVM and wants to access each others data structure, surely concurrency issues might pop out. If that is the case, I would suggest to create public static Object mutex = new Object() somewhere and synchronize( mutex ) { ... all critical operations ... }.

However, it might not be enough depending on what components you would like to use. For instance, WorldView is written the way that it should be thread-safe, but modules like AgentInfo, Players, etc. might not. You will have to experiment.

May be, if you can describe your scenario, I can provide you with more insights.

Cheers!
Jimmy

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=6&comments_reply_threadId=6&comments_parentId=1134&post_reply=1#form>




More information about the Pogamut-list mailing list