global data sharing and synchronization
-
- Posts: 15
- Joined: 29 Feb 2008
global data sharing and synchronization
Are the indicator and signal calculations in MultiCharts run on separate, independent threads? For sharing data between them, would it work to block the dependent indicator/signal with a mutex (in a dll) until the data from the independent indicator became available or would it crash, lock, or stall the program? Does MultiCharts have any inherent ways of sharing and synchronizing data between indicators and charts?
- Andrew Kirillov
- Posts: 1589
- Joined: 28 Jul 2005
- Has thanked: 2 times
- Been thanked: 31 times
- Contact:
Re: global data sharing and synchronization
If you run indicator and strategy on the same chart they are executed in the same thread.Are the indicator and signal calculations in MultiCharts run on separate, independent threads?
Thread-safe mechanism is implemented in MC to support function calls in custom DLLs.For sharing data between them, would it work to block the dependent indicator/signal with a mutex (in a dll) until the data from the independent indicator became available or would it crash, lock, or stall the program? Does MultiCharts have any inherent ways of sharing and synchronizing data between indicators and charts?
Re: global data sharing and synchronization
Andrew, does this mean if a study calls a function in a dll, and another study calls the same function at the same time, one will wait before calling it until the other has returned from that function? Also, if two studies call two different functions in a dll, will they be permitted to be called at the same time?Thread-safe mechanism is implemented in MC to support function calls in custom DLLs.
Hi
If they call the same function on the same thread in the DLL, (in the same DLL), The function will reply the strategy one by one, if the function is program on one thread.
But you could developp a multithread function in your DLL
The strategy will call in the same time, but they will wait the answer of the DLL.does this mean if a study calls a function in a dll, and another study calls the same function at the same time, one will wait before calling it until the other has returned from that function?
If they call the same function on the same thread in the DLL, (in the same DLL), The function will reply the strategy one by one, if the function is program on one thread.
But you could developp a multithread function in your DLL
My dll spawns a separate thread associated with a mutex so I can display windows, and to prevent clashes with some shared work variables in the dll. I also use a shared variable in the dll to block extra incoming "window type" calls to my dll from MC so my window functions (create, close, write text, etc.) are processed one at a time, at least that's what I thought. That's why I asked the questions.
So, I did a test. I wrote my own application that calls just one of the functions in my dll. My test app has two threads calling the same function at random. It works fine only when the two threads use a mutex to make sure they don't call the same function in my dll at exactly the same time. When I remove the mutex the program crashes at some stage. So, it looks like I need to do some more work to make my dll handle overlapping calls. It appears my blocking method is not good enough.
So, given the above test does MC also call the same function at the same time without waiting for the other call to finish? If it does then it will exhibit the same problem as my test app without the mutex.
So, I'm not sure what you mean by making a multi-threaded function in my dll. Can you please explain to me some more, or point to a site that explains this clearly in detail? Thanks.
UPDATE: After some more tests, I've finally got my test app and dll working when calling the same function at the same time. The key was using a named mutex in my dll so that the first caller of my function became the master and other calls were kept waiting. This is needed only for some of my functions, not all as others can be called upon concurrently (ie, thread safe). So, now I have to test this with MC - hopefully all is well now.
So, I did a test. I wrote my own application that calls just one of the functions in my dll. My test app has two threads calling the same function at random. It works fine only when the two threads use a mutex to make sure they don't call the same function in my dll at exactly the same time. When I remove the mutex the program crashes at some stage. So, it looks like I need to do some more work to make my dll handle overlapping calls. It appears my blocking method is not good enough.
So, given the above test does MC also call the same function at the same time without waiting for the other call to finish? If it does then it will exhibit the same problem as my test app without the mutex.
So, I'm not sure what you mean by making a multi-threaded function in my dll. Can you please explain to me some more, or point to a site that explains this clearly in detail? Thanks.
UPDATE: After some more tests, I've finally got my test app and dll working when calling the same function at the same time. The key was using a named mutex in my dll so that the first caller of my function became the master and other calls were kept waiting. This is needed only for some of my functions, not all as others can be called upon concurrently (ie, thread safe). So, now I have to test this with MC - hopefully all is well now.