Support Board
Date/Time: Sun, 09 Mar 2025 20:53:18 +0000
[Programming Help] - thread safe
View Count: 459
[2022-03-08 15:22:47] |
User824913 - Posts: 15 |
Hi to everyone, Is a global method defined like the code below safe? Is there a danger of another studio running the same code at the same time with a different thread? In this case is it possible to synchronize a method? Thks a lot // The top of every source code file must include this line #include "sierrachart.h" // For reference, refer to this page: // Advanced Custom Study Interface and Language (ACSIL) // This line is required. Change the text within the quote // marks to what you want to name your group of custom studies. SCDLLName("Provette") void test(int i){ //do the job } SCSFExport scsf_Provette(SCStudyInterfaceRef sc) Date Time Of Last Edit: 2022-03-08 15:28:26
|
[2022-03-08 16:33:29] |
Tony - Posts: 553 |
I would assume it's safe, I am using a few global functions. My situation is I have 2 studies, let's say, Provette1 and Provette2, both need to call test(), that was when things could get messed up, what I did was having some public arrays, example: int result[2] = {0,0}; and Provette1 always writes result in result[0] and Provette2 in result[1], it works very well, maybe there are better solutions. (all public variables can be accessed by all studies, even between different charts in the same chart book, which is very handy) // The top of every source code file must include this line #include "sierrachart.h" SCDLLName("Provette") int result[2] = {0, 0}; double other_result[2] = {0.0, 0.0}; void test(int i, int result_target){ //do the job result[result_target] = whatever_integer; other_result[result_target] = whatever_double; } SCSFExport scsf_Provette1(SCStudyInterfaceRef sc) { //codes test(whatever_input, 0); } SCSFExport scsf_Provette2(SCStudyInterfaceRef sc) { //codes test(whatever_input, 1); } Date Time Of Last Edit: 2022-03-08 16:43:07
|
[2022-03-08 16:44:20] |
Tony - Posts: 553 |
sorry, I forgot to add the calling part, just edited the previous post
|
[2022-03-08 17:35:31] |
User431178 - Posts: 612 |
There is no problem with global functions and thread safety, unless the functions are accessing/operating on data that is available to/used by the various threads simultaneously (e.g. global variables). Also, the charts/studies in SC are processed sequentially on a single thread, so, unless you are creating threads yourself, there should be no problem anyway. Date Time Of Last Edit: 2022-03-08 17:35:51
|
To post a message in this thread, you need to log in with your Sierra Chart account: