diff --git a/tests/test_reent.cpp b/tests/test_reent.cpp new file mode 100644 index 0000000..fbcbbc9 --- /dev/null +++ b/tests/test_reent.cpp @@ -0,0 +1,56 @@ + +#include +#include +#include + +#include + +#include "epanet2.h" + +#define NUM_THREADS 2 + +using namespace std; + +void epanet_thread(long i) +{ + int errorcode = 0; + EN_ProjectHandle ph; + + string prefix = "example_"; + string suffix = ".inp"; + string input = prefix + to_string(static_cast(i)) + suffix; + + suffix = ".rpt"; + string report = prefix + to_string(static_cast(i)) + suffix; + + suffix = ".out"; + string output = prefix + to_string(static_cast(i)) + suffix; + + printf("Thread #%ld starting EPANET ...\n", i); + + EN_createproject(&ph); + errorcode = EN_runproject(ph, input.c_str(), report.c_str(), output.c_str(), NULL); + EN_deleteproject(&ph); + + printf("Thread #%ld EPANET done. Status = %d\n", i, errorcode); +} + +int main(int argc, char *argv[]) +{ + long i; + boost::thread *threads[NUM_THREADS]; + + for (i = 0; i < NUM_THREADS; i++) { + threads[i] = new boost::thread(epanet_thread, i); + printf("Main: creating thread %ld.\n", i); + } + + for (i = 0; i < NUM_THREADS; i++) { + threads[i]->join(); + printf("Main: joining thread %ld.\n", i); + delete threads[i]; + } + + printf("Main: program completed. Exiting.\n"); + return(0); +}