Related articles |
---|
Lexer/Parser in Multithreaded C App isaacson@blue.seas.upenn.edu (1998-07-03) |
Re: Lexer/Parser in Multithreaded C App cfc@world.std.com (Chris F Clark) (1998-07-05) |
From: | Chris F Clark <cfc@world.std.com> |
Newsgroups: | comp.compilers |
Date: | 5 Jul 1998 22:03:44 -0400 |
Organization: | The World Public Access UNIX, Brookline, MA |
References: | 98-07-022 |
Keywords: | parse, parallel |
isaacson@blue.seas.upenn.edu (Ron Isaacson) asked some questions about
thread safety.
While, I have not used the bison and/or flex features for such. You
should be able to get thread safety without C++. The key is to keep
all global values in a data structure and have one data structure per
thread. Most C++ versions do this by default, since the normal coding
style for C++ is to keep global data as memebers of the class.
However, the same technique can be done in C.
To solve your own global data problem, you simply do the same thing.
Move your global data to a data structure which you keep one per
thread.
Of course, that only works if the global data for each thread is
independent of the global data of the other threads. If you have some
global data which you want to share between threads, then you have to
do the hard thing and use some form of synchronization primitives,
such as locks, semaphores, or monitors. By the way, the lexers and
parsers are only thread safe as long as each thread is parsing
independently--if you want to threads to share one parser and
synchronize their access to the global data, you will probably have to
write that version yourself--I've never seen a parser which does
that--of course, it also isn't what you're likely to want either.
Hope this helps,
-Chris
*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. CompuServe : 74252,1375
3 Proctor Street voice : (508) 435-5016
Hopkinton, MA 01748 USA fax : (508) 435-4847 (24 hours)
------------------------------------------------------------------------------
Web Site in Progress: Web Site : http://world.std.com/~compres
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.