compile_string not thread safe
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=1739
Reported by Marcus Wellhardh wellhard@roxen.com
The following testcase gives some backtraces telling that 'foo' is undefined even if a resolver is used when compiling the string. If the mutex in the code is uncommented no backtrace is returned.
Thread.Mutex m = Thread.Mutex();
int threads = 0;
class Compile
{
void go(string txt)
{
threads++;
if (mixed err = catch {
for(int i; i < 1000; i++)
{
program res;
// Thread.MutexKey l = m->lock();
res = compile_string (
txt, 0,
class (object master) {
mixed resolv (string id, void|string file)
{
return "bar";
}
} (master()));
// l = 0;
}
})
werror (describe_backtrace (err));
if (!--threads) exit (0);
}
}
int main()
{
for(int t = 0; t < 10; t++)
{
Compile compile = Compile();
thread_create(compile->go, "string f1() { return foo; }");
}
return -17;
}
Output:
| -:1:'foo' undefined.
| Compilation failed.
| /home/wellhard/projects/pike-7.2/build/sunos-5.8-i86pc/master.pike:172:
| master()->compile_string("string f1() { return foo;
}",0,gc.pike.Compile.__class_65595_0())
| gc.pike:23: go("string f1() { return foo; }")