Thread Safety in Concurrent Environments

Questions on using the Translate actionscript compiler.

Thread Safety in Concurrent Environments

Postby yixiel » Wed Jun 28, 2006 9:38 am

Hi, I have some sort of less than usual question, but it's quite important to me. Is the class ASParser thread-safe? Here's the scenario:

A server receives requests from n clients at one particular instant and needs to generate a SWF for each request (in parallel that is). Now, what do you recommend? Should I use an ASParser for each movie to compile it's scripts or is it possible to use just one ASParser instance to compile all the scripts for all the movies? In other words, is ASParser thread-safe (and without using synchronize) ?

Thank you very much for your support!
yixiel
 
Posts: 5
Joined: Thu May 11, 2006 2:08 pm

Postby smackay » Wed Jun 28, 2006 11:42 am

First the bad news: The parser is currently NOT thread-safe.

Now for the good news: It would be simple to make it thread-safe. The only instance variables are used to report errors in the script. They can easily be converted to variables local to the parse() method.

Of course this comes with a big IF ? The parser contains a lot of code generated by JavaCC there might be some kind of side effect so I need to look through the code to be sure.

If thread-safety would be a big thing for you let me know and I will add it to the ToDo list.

Regards,

Stuart
smackay
Site Admin
 
Posts: 594
Joined: Sat Sep 03, 2005 9:04 am

Postby yixiel » Wed Jun 28, 2006 3:44 pm

That depends. I think I can get away for now by making a static wrapper class with a synchronized static method named compile() which in turn masks this only one instance of ASParser and invokes parse() on it safely.

There is only one question to my method, whether there is a performance drop from applying it or not. If the ASParser parse method is 100% busy anyway, I think forcing sequential parsing instead of parallel parsing would take exactly the same amount of time. In that case I don't really need "thread-safety".

Anyway, I do appreciate your information, it was kind of useful, and ... please, keep up the good work!

Cheers
yixiel
 
Posts: 5
Joined: Thu May 11, 2006 2:08 pm


Return to Using Translate

Who is online

Users browsing this forum: No registered users and 0 guests