42
my $grammar = <<'EOF';
43
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
45
<element name="foo"><empty/></element>
49
my $r = XML::LibXML::RelaxNG->new(string=>$grammar);
51
threads->new(sub { XML::LibXML::RelaxNG->new(string=>$grammar) });
53
$_->join for(threads->list);
59
eval { XML::LibXML->new->parse_string('foo') };
61
threads->new(sub { eval { XML::LibXML->new->parse_string('foo') } for(1..1000); 1; });
63
$_->join for(threads->list);
68
print "accessing document elements without lock\n";
70
my $doc=XML::LibXML::Document->new;
71
$doc->setDocumentElement($doc->createElement('root'));
72
$doc->getDocumentElement->setAttribute('foo','bar');
75
# # a dictionary of $doc
76
# my $el =$doc->createElement('foo'.$_);
77
# $el->setAttribute('foo','bar');
81
for my $t_no (1..40) {
84
$doc->getDocumentElement;
89
$_->join for(threads->list);
92
print "operating on different documents without lock\n";
95
my $doc = XML::LibXML::Document->new;
96
$doc->setDocumentElement($doc->createElement('root'));
97
$doc->getDocumentElement->setAttribute('foo','bar');
99
for my $t_no (1..40) {
101
my $doc=$docs[$t_no-1];
103
# a dictionary of $doc
104
my $el =$doc->createElement('foo'.$_);
105
$el->setAttribute('foo','bar');
106
$doc->getDocumentElement->getAttribute('foo');
107
$el->getAttribute('foo');
112
$_->join for(threads->list);
115
print "operating on the same document with a lock\n";
118
my $doc=XML::LibXML::Document->new;
119
for my $t_no (1..40) {
122
lock $lock; # must lock since libxml2 uses
123
# a dictionary of $doc
124
my $el =$doc->createElement('foo');
125
$el->setAttribute('foo','bar');
126
$el->getAttribute('foo');
131
$_->join for(threads->list);
38
136
<?xml version="1.0" encoding="utf-8"?>
39
137
<root><node><leaf/></node></root>
42
# Spawn threads with a document in scope
140
print "Spawn threads with a document in scope\n";
44
142
my $doc = $p->parse_string( $xml );
45
143
for(1..MAX_THREADS)
245
343
$p = XML::LibXML->new();
344
print "parse a big file using the same parser\n";
248
346
for(1..MAX_THREADS)
250
348
threads->new(sub {
251
349
open my $fh, "<$bigfile";
350
my $doc = $p->parse_fh($fh);
355
my @results = $_->join for(threads->list);
360
print "create elements\n";
362
my @n = map XML::LibXML::Element->new('bar'.$_), 1..1000;
366
push @n, map XML::LibXML::Element->new('foo'.$_), 1..1000;
376
my $e = XML::LibXML::Element->new('foo');
377
for(1..MAX_THREADS) {
380
my $d = XML::LibXML::Document->new();
381
$d->setDocumentElement($d->createElement('root'));
382
$d->documentElement->appendChild($e);
387
$_->join for(threads->list);
389
print $e->ownerDocument->toString(),"\n";
394
my $e = XML::LibXML::Element->new('foo');
395
my $d = XML::LibXML::Document->new();
396
$d->setDocumentElement($d->createElement('root'));
397
for(1..MAX_THREADS) {
400
$d->documentElement->appendChild($e);
405
$_->join for(threads->list);
407
print $e->ownerDocument->toString(),"\n";
412
my $e = XML::LibXML::Element->new('foo');
413
for(1..MAX_THREADS) {
416
XML::LibXML::Element->new('root')->appendChild($e);
421
$_->join for(threads->list);
423
print $e->parentNode->toString(),"\n";