Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6970355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:41:59+00:00 2026-05-27T16:41:59+00:00

Does Spirit provide any capabilities for working with non-blocking IO? To provide a more

  • 0

Does Spirit provide any capabilities for working with non-blocking IO?

To provide a more concrete example: I’d like to use Boost’s Spirit parsing framework to parse data coming in from a network socket that’s been placed in non-blocking mode. If the data is not completely available, I’d like to be able to use that thread to perform other work instead of blocking.

The trivial answer is to simply read all the data before invoking Spirit, but potentially gigabytes of data would need to be received and parsed from the socket.

It seems like that in order to support non-blocking I/O while parsing, Spirit would need some ability to partially parse the data and be able to pause and save its parse state when no more data is available. Additionally, it would need to be able to resume parsing from the saved parse state when data does become available. Or maybe I’m making this too complicated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:41:59+00:00Added an answer on May 27, 2026 at 4:41 pm

    TODO Will post a example for a simple single-threaded ‘event-based’ parsing model. This is largely trivial but might just be what you need.

    For anything less trivial, please heed to following considerations/hints/tips:


    How would you be consuming the result? You wouldn’t have the synthesized attributes any earlier anyway, or are you intending to use semantic actions on the fly?

    That doesn’t usually work well due to backtracking. The caveats could be worked around by careful and judicious use of qi::hold, qi::locals and putting semantic actions with side-effects only at stations that will never be backtracked. In other words:

    • this is bound to be very errorprone
    • this naturally applies to a limited set of grammars only (those grammars with rich contextual information will not lend themselves well for this treatment).

    Now, everything can be forced, of course, but in general, experienced programmers should have learned to avoid swimming upstream.

    Now, if you still want to do this:

    You should be able to get spirit library thread safe / reentrant by defining BOOST_SPIRIT_THREADSAFE and linking to libboost_thread. Note this makes the gobals used by Spirit threadsafe (at the cost of fine grained locking) but not your parsers: you can’t share your own parsers/rules/sub grammars/expressions across threads. In fact, you can only share you own (Phoenix/Fusion) functors iff they are threadsafe, and any other extensions defined outside the core Spirit library should be audited for thread-safety.

    If you manage the above, I think by far the best approach would seem to

    • use boost::spirit::istream_iterator (or, for binary/raw character streams I’d prefer to define a similar boost::spirit::istreambuf_iterator using the boost::spirit::multi_pass<> template class) to consume the input. Note that depending on your grammar, quite a bit of memory could be used for buffering and the performance is suboptimal
    • run the parser on it’s own thread (or logical thread, e.g. Boost Asio ‘strands‘ or its famous ‘stackless coprocedures’)
    • use coarse-grained semantic actions like shown above to pass messages to another logical thread that does the actual processing.

    Some more loose pointers:

    • you can easily ‘fuse’ some functions to handle lazy evaluation of your semantic action handlers using BOOST_FUSION_ADAPT_FUNCTION and friends; This reduces the amount of cruft you have to write to get simple things working like normal C++ overload resolution in semantic actions – especially when you’re not using C++0X and BOOST_RESULT_OF_USE_DECLTYPE
    • Because you will want to avoid semantic actions with side-effects, you should probably look at Inherited Attributes and qi::locals<> to coordinate state across rules in ‘pure functional fashion’.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one use boost::spirit with an input that consists of something other than
Does anyone use have a good regex library that they like to use? Most
In the spirit of question Java: Why does MaxPermSize exist? , I'd like to
Does anyone have a working, step-by-step example of how to implement IEnumerable and IEnumerator
I tried to modify the mini_c example of boost::spirit to match to my existing
Does anybody know any good resources for learning how to program CIL with in-depth
Does anyone know how to get IntelliSense to work reliably when working in C/C++
Does anyone have any recommendations of tools that can be of assistance with moving
Does C# have built-in support for parsing strings of page numbers? By page numbers,
i found this in this file: http://www.boost.org/doc/libs/1_43_0/boost/spirit/home/phoenix/core/actor.hpp What does this syntax means? struct actor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.