🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Multiple VMs in multiple threads/fibers

Started by
5 comments, last by WitchLord 16 years, 8 months ago
Hi all, I am currently researching scripting languages and techniques for an upcoming project and find Angelscript very promising (both syntax and API). Unfortunately I can't tell you exactly what I will be coding, but it will need to run a lot of scripts (1000+) simultaneously, must be really fast and wait for I/O to complete. Basically my idea is to use multiple threads in which multiple fibers will run, each fiber will have it's own Angelscript VM/Engine. When an I/O operation (such as reading from a file), or another operation that might take some time is initiated, the host application schedules another fiber (and thus VM) to run until it finishes the script or encounters an I/O operation itself. The scripts don't need access to eachother's data, so there's no need for locking etc. I briefly looked at the concurrent sample in the Angelscript distribution and it looks promising (so that I might not need fibers at all). I am aware of the fact that compiled native code would be the fastest way of doing things, but the end-user must be able to change the behaviour of the program, so that's not an option. The end-user also doesn't have extensive programming experience. My question to you guys is: Are my goals feasible at all? Are there any quirks or bugs that might cause trouble when Angelscript is run in multiple threads? Is it fully reentrant? Btw, the I/O operations will probably cause the biggest delays, so an overhead of about 10 ms per script (compared to native code) won't be a big problem imo. Thanks in advance! - PsyQo
Advertisement
I can't give any guarantees towards the performance, but AngelScript should be able to do what you describe.

You need to compile the library with the preprocessor flag USE_THREADS for it to work completely. This adds critical sections for the few places where multiple engines/contexts may intersect within the library itself. It also adds threadlocal storage for some parts, such as the string buffer when returning function declarations, or the context stack interacted with through asGetActiveContext.

As far I know there are no quirks or bugs that should make AngelScript invaliable in a multithreaded environment. In fact other developers have already written multithreaded applications with script executions in various threads.

What OS are you programming for. AngelScript is currently only prepared to run multithreaded on Windows OS. I have received code for adding the support to other platforms as well, but I haven't gotten to it yet. If you need it I can try to increase the priority on that.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for your reply Andreas!

Initially the application will run on Windows only, but in the future I might need to do a linux port, so threadsafe operation on other platforms would be very welcome, but isn't a priority for me atm.

So, if I understand you correctly, multiple asIScriptEngine instances will access shared data (that will need locking when used across multiple threads)?

I think I'll write a simple testcase to test some things. If I encounter something interesting I'll let you know.

Thanks again!
anyway, using AS_THREADS currently doesn't work in latest version. you better grab <2.8.x or something
It doesn't? I wasn't aware of that.

I'll have to investigate this.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

i don't know what's happening, but it seems that latest changes in the svn trunk aren't so well tested.

ops sorry, was my fault, for some strange reason, i've not taken into account the updated angelscript.h file...

[Edited by - kunitoki on October 11, 2007 2:48:07 PM]
Oops, indeed. ;)

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement