Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2008-07-27 14:18:29

I've just discovered the existence of these manifest constants in spirit
and checked the documentation and code to determine what they do.

Of course figuring what spirt code does and how it does is not
easy to get right for the casual observer so feel free to correct
and any mis-conceptions / conclusions that I 've got.

My general conception is that parsing can be consider
as various quasi - independent phases.

a) specification of grammar - source code preparation
b) compiliation
c) instantiontion/construction of grammar definition
d) usage of c) to parse a text string
e) destruction of instance.

>From this I want to conclude that phase d) does not change
the grammar definition so so that in a multi-threading
environment, the invocation of the scoped_lock
would be limited to phases c) and e).

That is, I want to believe that the following example adapted
from the spirit documentation would work:

    const my_grammar g; // note addition of const

    if (parse(first, last, g, space_p).full)
        cout << "parsing succeeded\n";
        cout << "parsing failed\n";

The reason I ask is that the serialization library uses
spirit to parse xml archives. Recently, I made changes
to make the library thread-safe. I did this without using
mutexes/locks by confine all non-const operations to
construction and destruction and using static object
constructed/destructed at pre-main and post main
time time. Although the jury is still out on this, I believe
it will make the serialization library thread safe without
the need for using threading primitives and libraries.

I never realised that spirt wasn't thread-safe.
I would like this approach to include xml_archives. So
my quesion is: Can I instantiate my xml grammar as
a static variable at pre-execution time and permit it
to be used by mulitipe threads without locking?

Robert Ramey

Boost list run by bdawes at, gregod at, cpdaniel at, john at