volatile GeDialog
-
On 20/07/2016 at 10:56, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R17
Platform: Windows ;
Language(s) : C++ ;---------
Hello.I have a GeDialog that is supposed to be unique. A command plugin allocates a global variable and no further instances will be created in the whole code.
The problem comes when I want different threads to access its Data container (only Get methods).
The main thread gets the values correctly, but the other threads get wrong values.
I try to deal with this problem by using the volatile keyword.
I know that I have to use mutex in a later stage but for now I get compile errors.Here is a very simplified version of the code:
volatile MyGeDialog* any_dialog; void callGet() { Int32 val; any_dialog->GetInt32(123123, val); }
I get the following error which is caused when the volatile keyword is used:
no instance of overloaded function "MyGeDialog::GetInt32" matches the argument list and object (the object has type qualifiers that prevent a match)
argument types are: (int, Int32)
object type is: volatile MyGeDialogThank you for your time.
-
On 21/07/2016 at 02:25, xxxxxxxx wrote:
Hello,
in Cinema 4D any GUI related operation is only allowed from the main thread. Therefore I'm not surprised that accessing a GeDialog from another thread causes problems. I strongly suggest to come up with another solution. Maybe introduce a static class that stores the relevant data and provides thread safe functions to access the data. The Cinema 4D API provides several semaphore and spin lock classes that can be used to ensure save access.
I'm not an C++ guru but I think the "volatile" keyword has nothing to do with making a resource thread safe and is not useful to solve this problem.
Best wishes,
Sebastian -
On 21/07/2016 at 03:37, xxxxxxxx wrote:
Hello.
I don't use volatile for safety. I have mutex for that. The problem was that the data didn't have the correct values. I came up with another solution that provides the correct Dialog's data in other threads.
Thank you very much for your time.