In order to test a vendor's DLL in a multi-threaded environment, I want to make sure that specific methods can be called in parallel.
For now I just spawn a few threads and do some operations, but I have no control over which operations are happening at the same time.
I'm a bit lost as to what I should use, between locks and monitors, waithandles, mutex, etc.
It's just for a test app, so no need to be "best practice", I just want to make sure rotating (fast operation) on thread 1 is running at the same time as loading (slow operation) on thread 2.
This is basically what I need:
var thread1 = new Thread(() => {
// load the data ; should take a few seconds
Vendor.Load("myfile.json");
// wait for the thread 2 to start loading its data
WaitForThread2ToStartLoading();
// while thread 2 is loading its data, rotate it
for (var i = 0; i < 100; i++) {
Vendor.Rotate();
}
});
var thread2 = new Thread(() => {
// wait for thread 1 to finish loading its data
WaitForThread1ToFinishLoading();
// load the data ; should take a few seconds
Vendor.Load("myfile.json");
// this might run after thread 1 is complete
for (var i = 0; i < 100; i++) {
Vendor.Rotate();
}
});
thread1.Start();
thread2.Start();
thread1.Join();
thread2.Join();
I have done something with locks and booleans, but it doesn't work.