Threading model in 2X?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
ericheimburg
Posts: 26
Joined: 18 Mar 2010, 07:25

Threading model in 2X?

Post by ericheimburg »

Hi, just getting started with the new version and enjoying it so far. But I don't see any documentation on what threads are used where in the server. In 1.x, for instance, scheduled tasks happened on one thread (and could never overlap each other), other event handlers happened in multiple additional threads depending on how it was set up...

Are there rules of thumb for 2X?

And more specifically -- I find that adding thread-safety to complex gameplay logic is almost never worth the time it takes to develop and debug, so I want to get all my gameplay-logic message handlers to happen in a single thread per game room. Is there an easy way to make that happen? (I can, of course, queue up incoming events manually into a custom thread that handles them synchronously... I'm just wondering if there's an easier way.)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Hi. We'll publish more details on this very soon. The general approach is that the server API provide 99.9% of thread safe objects (i.e. Rooms, Users etc...) with the only exception being the SFSObject and SFSArray.

(Typically these objects are used as local vars and don't incur in concurrency issues.)

The SFS2X environment is multi-threaded so global data in your main extension must always be thread safe. I don't agree very much with your comment about thread safety not being worth. Actually it is very much. All you need to do is making sure that shared state in your game is protected against corruption under concurrent thread access.

With today's JDK 1.6 this should pretty smooth with the help of the java.util.concurrent packages.

As regards having the same thread accessing one extension every time this is not possible and it would trade lots of performance for a bit more of developer's convenience.
Plus, anyways, the moment you add a Timer or scheduled task you have lost thread safety again :D

BOTTOM LINE: API are all thread safe (besides SFSarray and SFSObject), the rest is up to you. If you are familiar with Java web development, it's a similar situation.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply