GPLEX/GPPG Multithreading

Apr 21, 2015 at 12:48 PM
Edited Apr 21, 2015 at 3:33 PM
Hi,
I'm programing a compiler (DLL) and I would really like to use GPLEX/GPPG (Version 1.5.1) for parsing the source files. One requirement of the compiler is that multiple instances, each running in a seperate thread, can run simultanously. As described in the GPLEX/GPPG documentation this should be possible (because they are thread safe) :)

When it comes to multithreading in my implementation GPLEX/GPPG is crashing in strange ways - there are no problems when used single-threaded (sequential).

I'll try to show what i did (pseudo code)
// in Compiler.DLL
public class Compiler
{
    // some non-static methods / constructor
    ...

    public void compile()
    {
        //Create new instances
        Scanner scanner = new Scanner(mainSourcefile, parameters);
        Parser parser = new Parser(scanner);
        
        parser.Parse(ref intermediateLanguage);

        createBinaryOutput(intermediateLanguage);
    }
}
// In test assembly
public class Test
{
     public void compileWorker(Compiler c, String mainSourcefile)
     {
          c.compile(mainSourceFile);
     }

     public void test()
     {
          List<Compiler> cl = new List<Compiler>();
          
          // fill Compiler list....

          foreach(Compiler c in cl)
          {
               Thread t = new Thread(() => compileWorker(c, mainSourceFile));
               t.Start();
          }
     }
}
Im getting following Errors
  • IndexOutOfRangeException (variable tos is negative) in Function Pop() -> ShiftReduceParserCode.cs
  • FsaState.ParserTable is null in function Parse() -> ShiftReduceParserCode.cs
  • FileStream disposed (very strange)
In the constructor of the Scanner Im Setting the source (could this be a Problem?):
internal Scanner(string pathMainSource,)
{
    try
    {
        FileStream fs = new FileStream(pathMainSource, FileMode.Open, FileAccess.Read, FileShare.Read);
            
        SetSource(fs);
        fsStack.Push(fs);
    }
}
The filestream is closed in yywrap() as suggested in the documentation.

Did I overlook something or did I misinterpret the documentation?

I would be very happy if someone could help me :)
Thanks a lot in advance

UPDATE: It seems that I somehow manged to call the compileWorker() on one object over and over :P
My bad - works fine now