On Wednesday, 5 October 2016 at 07:36:58 UTC, Jonathan M Davis wrote:
On Tuesday, October 04, 2016 19:22:10 Begah via Digitalmars-d-learn wrote:
How can I make a method that accepts being called by both a shared and non-shared object, to prevent having to copy methods and adding a "shared"?

You could templatize them, but really, the idea is that you _don't_ call much of anything on a shared object. It's not thread-safe to do so unless it's protected by a mutex or sychronized block. shared is as unwieldy as it is in part because it's easy to use incorrectly, and most code should not be using shared at all, because the stuff that actually needs to be shared across threads is normally pretty minimal.

Thanks for the reply,

One of my problem is that, i need all of my data to be accessible by both threads ( I have two ). I am making a 3d application and decided to separate the update loop and the render loop ( I just created another thread for the update loop meanwhile the render loop has to remain on the main thread ).

I just want to ensure that when my render loop ( or update loop ) updates/render an object, the other loop cannot ( To avoid potential bugs whereas one loop changes the position component and the render loop renders the object with only the new x position because the y and z variable haven't been changed yet ).

As i will have many of those objects, do i need to create a mutex for everyone of them?

Reply via email to