Project

Profile

Help

Revision 5401a5ae

Added by O'Neil Delpratt almost 2 years ago

Saxon/C Development

View differences:

latest9.9/hec/samples/cppTests/testXSLT.cpp
1 1
#include <sstream>
2

  
2
#include <stdio.h>
3
#include <cstdlib>
4
#include <pthread.h>
5
#include <unistd.h>
6
#include <thread>
3 7
#include "../../Saxon.C.API/SaxonProcessor.h"
4 8
#include "../../Saxon.C.API/XdmValue.h"
5 9
#include "../../Saxon.C.API/XdmItem.h"
......
706 710
}
707 711

  
708 712

  
713
void *RunThread(void *args) {
714

  
715
    struct arg_struct *argsi = (struct arg_struct *)args;
716
    int threadid = argsi->id;
717
    Xslt30Processor * trans = argsi->trans;
718
    long tid;
719
    tid = (long)threadid;
720

  
721
    trans->attachThread();
722

  
723
   trans->setInitialMatchSelectionAsFile("../php/xml/foo.xml");
724

  
725
    const char *result = trans->applyTemplatesReturningString();
726
    cout<<" Result from THREAD ID: "<< tid << ", " << result<<endl;
727
    delete result;
728
    //pthread_exit(NULL);
729
    trans->detachThread();
730
}
731

  
732
void testThreads (SaxonProcessor * processor) {
733
    pthread_t threads[NUM_THREADS];
734
    int rc;
735
    int i;
736

  
737
    Xslt30Processor *  trans = processor->newXslt30Processor();
738

  
739
    trans->compileFromFile("../php/xsl/foo.xsl");
740
    struct arg_struct args;
741
    args.trans = trans;
742

  
743
    for( i = 0; i < NUM_THREADS; i++ ) {
744
        cout << "main() : creating thread, " << i << endl;
745
        args.id = i;
746
        rc = pthread_create(&threads[i], NULL, RunThread, (void *)&args);
747

  
748
        if (rc) {
749
            cout << "Error:unable to create thread," << rc << endl;
750
            exit(-1);
751
        }
752
	(void) pthread_join(threads[i], NULL);
753
    }
754
  //  pthread_exit(NULL);
755
}
756

  
757

  
709 758

  
710 759
int main()
711 760
{

Also available in: Unified diff