Threads

[Raku LibXML Project] / [LibXML Module] / Threads

Notes on Raku LibXML Threading and Concurrency

Concurrency and Parsing

Parsing, including, validation and the Reader pull-parser can be run concurrently.

my @docs = @files.hyper.map: -> $file { LibXML::Parse: :$file }

However, the Raku LibXML bindings will protect these with a commonly library lock, defeating concurrency, if the libxml library has not been compiled with threading enabled. Threading can be checked using the LibXML::Config threads method.

unless LibXML::Config.threads { ... }

Concurrency and Input Callbacks

Input callbacks may be set globally, without affecting concurrency.

my LibXML::InputCallback $input-callbacks .= new: @callbacks;
LibXML::Config.input-callbacks = $input-callbacks;

They may also be set at the parser level. However, this is not thread safe. The LibXML library requires that you also enable the parser-locking flag, which limits concurrent parsing.

LibXML::Config.parser-locking = True;
my LibXML::InputCallback $input-callbacks .= new: :callbacks{
        :&match, :&read, :&open, :&close
}
LibXML::Config.parser-locking = True;
my LibXML:D $parser .= new: :$input-callbacks;

DOM Concurrency

Parallel Construction

Document fragments and element sub-trees, may be constructed in parallel provided that they remain independent of each other. They then need to be assembled sequentially to create the final document:

my LibXML::Document $doc .= parse: :string("<doc/>");
my @frags = @files.hyper.map: -> $file { LibXML::DocumentFragment.parse: :balanced, :$file}
$doc.addChild($_) for @frags;

DOM Updates and Concurrency

It is not thread-safe to read and modify DOM nodes concurrently.

However, each node has a protect method that can be used to limit concurrency.

$elem.protect: { $elem.appendChild: LibXML::Element.new('foo') }

Be careful with nesting protect calls, to avoid potential deadlocks.

LibXML v0.11.3

Raku bindings to the libxml2 native library

Authors

  • David Warring

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • LibXML
  • LibXML::Attr
  • LibXML::Attr::Map
  • LibXML::CDATA
  • LibXML::Comment
  • LibXML::Config
  • LibXML::Dict
  • LibXML::Document
  • LibXML::DocumentFragment
  • LibXML::Dtd
  • LibXML::Dtd::AttrDecl
  • LibXML::Dtd::ElementContent
  • LibXML::Dtd::ElementDecl
  • LibXML::Dtd::Entity
  • LibXML::Dtd::Notation
  • LibXML::Element
  • LibXML::EntityRef
  • LibXML::Enums
  • LibXML::ErrorHandling
  • LibXML::HashMap
  • LibXML::InputCallback
  • LibXML::Item
  • LibXML::Namespace
  • LibXML::Node
  • LibXML::Node::List
  • LibXML::Node::Set
  • LibXML::PI
  • LibXML::Parser
  • LibXML::Parser::Context
  • LibXML::Pattern
  • LibXML::PushParser
  • LibXML::Raw
  • LibXML::Raw::DOM::Attr
  • LibXML::Raw::DOM::Document
  • LibXML::Raw::DOM::Element
  • LibXML::Raw::DOM::Node
  • LibXML::Raw::Defs
  • LibXML::Raw::Dict
  • LibXML::Raw::HashTable
  • LibXML::Raw::RelaxNG
  • LibXML::Raw::Schema
  • LibXML::Raw::TextReader
  • LibXML::Reader
  • LibXML::RegExp
  • LibXML::RelaxNG
  • LibXML::SAX
  • LibXML::SAX::Builder
  • LibXML::SAX::Handler
  • LibXML::SAX::Handler::SAX2
  • LibXML::SAX::Handler::SAX2::Locator
  • LibXML::SAX::Handler::XML
  • LibXML::Schema
  • LibXML::Text
  • LibXML::Types
  • LibXML::Utils
  • LibXML::X
  • LibXML::XInclude::Context
  • LibXML::XPath::Context
  • LibXML::XPath::Expression
  • LibXML::XPath::Object
  • LibXML::_CharacterData
  • LibXML::_Collection
  • LibXML::_Configurable
  • LibXML::_DomNode
  • LibXML::_Options
  • LibXML::_ParentNode
  • LibXML::_Rawish
  • LibXML::_Validator

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.