Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 358352 - GrammarAccess unsufficiently synchronized
Summary: GrammarAccess unsufficiently synchronized
Status: VERIFIED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: v2.7
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-21 03:17 EDT by Mark Christiaens CLA
Modified: 2014-08-22 04:53 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Christiaens CLA 2011-09-21 03:17:56 EDT
Build Identifier: 20110615-0604

The generated grammar access class (in my case VhdlGrammarAccess) is a singleton.  It's used all over the place by multiple threads so needs good synchronization.  I'm worried about the lazy initialization that occurs.  For every grammar element, X, there is a pX field that is initialized to null.  That field is then lazily initialized when getXAccess() is invoked.  There is a serious risk that the pX field will be initialized multiple times and therefor that there are multiple XElements and ParserRules floating around corresponding to the same grammar entries.  That means in turn that identity comparisons can fail.  I haven't seen this actually occur in the wild but who knows. 

On a side note, I kind of doubt (but haven't checked this) that the lazy initialization does any good in this context.  I would imagine that all grammar elements will be needed in any serious use case.  Lazily initializing them seems to incur a continuous overhead that doesn't repay itself?


Reproducible: Always
Comment 1 Sven Efftinge CLA 2011-09-21 03:28:31 EDT
+1 for eager and thread safe initialization

Btw.: It looks like org.eclipse.xtext.service.GrammarProvider.getGrammar(Object) was made thread safe on purpose but I doubt it is, because of the EPackage initialization. Comments?
Comment 2 Sven Efftinge CLA 2011-09-21 03:29:43 EDT
(In reply to comment #1)
> Btw.: It looks like
> org.eclipse.xtext.service.GrammarProvider.getGrammar(Object) was made thread
> safe on purpose but I doubt it is, because of the EPackage initialization.
> Comments?

Forget it, I missed the inner if block.
Comment 3 Sebastian Zarnekow CLA 2014-08-07 08:13:19 EDT
Pushed to review