[stringtemplate-interest] Thread safety issue in Template .NET
Sam Harwell
sam at tunnelvisionlabs.com
Wed Jan 25 06:43:55 PST 2012
Hi James,
The CompiledTemplate (impl) is intended to only be read inside Template.Add.
I'll update it to be safe when impl.HasFormalArgs is false. If you are using
group files (*.stg) or the new template files (*.st with a proper template
header/formal arguments), then impl.HasFormalArgs will always be true.
Thanks,
--
Sam Harwell
Owner, Lead Developer
Description: Description: C:\Users\sam\Documents\Work\TVL\tvl_logo_small.png
http://tunnelvisionlabs.com <http://tunnelvisionlabs.com/>
From: James P. Moring [mailto:jmoring at gmail.com]
Sent: Wednesday, January 25, 2012 7:37 AM
To: stringtemplate-interest at antlr.org
Subject: [stringtemplate-interest] Thread safety issue in Template .NET
The Add method of Template is synchronized. This is used to guard access to
the shared member impl. A synchronized method only locks the method for
calls on the same instance thus leaving impl to be accessed via multiple
threads. The method should employ a lock on impl as follows or am I missing
something? Thanks
lock(impl)
{
if( impl.HasFormalArgs )
...
else
....
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120125/fd07d081/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2620 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20120125/fd07d081/attachment.png
More information about the stringtemplate-interest
mailing list