Which kind of thread safety is provided by Chaiscript


#1

Hi,

We can read that Chaiscript is thread safe by default, and that we can disable it to improve the performance.

For what I have understood this means that multiple threads can call the same script engine without problems, knowing that user objects must be protected themselves.

I have multiples threads and each owns a script engine. Do I need the threading support in this case ?

Even that I have enabled it (default), the helgrind tool reports many potentials race conditions. Can I ignore them or something is really at risk ?

See log at https://pastebin.com/4pz10p3U

Philippe


#2

Correct, if you disable thread safety but have only one thread accessing each ChaiScript interpreter you should be fine.

I think that code is OK that helgrind is warning on, but you are clearly using a very old version of ChaiScript that is no longer supported. In ChaiScript 6.0 the function add_reserved_word doesn’t even exist any longer.


#3

We have tried the following hello_world in a multi-threaded test application with the latest release of Chaiscript

/// main.cpp

#include <chaiscript/chaiscript.hpp>
#include
#include

static const int num_threads = 10;

std::string helloWorld(const std::string &t_name) {
return "Hello " + t_name + “\n”;
}

void call_from_thread() {
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&helloWorld), “helloWorld”);

chai.eval(R"(
puts(helloWorld(“Bob”));
)");
}

int main() {

std::thread t[num_threads];

//Launch a group of threads
for (int i = 0; i < num_threads; ++i) {
t[i] = std::thread(call_from_thread);
}

std::cout << “Launched from the main\n”;

//Join the threads with the main thread
for (int i = 0; i < num_threads; ++i) {
t[i].join();
}

return 0;
}

It was compiled with: g++ (GCC) 4.9.1 20140922 (Red Hat 4.9.1-10)

Running: valgrind --tool=helgrind ./chai_thread still reports a lot of possible data race

See log at: https://pastebin.com/LN65una4

Can you check if the errors can safely be ignored ?

Philippe