SFML community forums

Help => System => Topic started by: FleshyOverlord on January 26, 2020, 04:22:36 am

Title: Non-Locked threads and Locked Threads
Post by: FleshyOverlord on January 26, 2020, 04:22:36 am
If a non-locked thread tries to access data inside of a locked thread, will it be blocked from doing so?
Title: Re: Non-Locked threads and Locked Threads
Post by: Laurent on January 26, 2020, 09:54:44 am
Data are not "inside threads". Data live in memory, and any thread can read/write that memory. Threads are not "locked", but they can explicitly wait until some resource (data) becomes available.

You can use synchronization primitives, the simplest being the mutex, to ensure safe access to these shared locations in memory between threads.

I suggest that read more about multithreading and concurrent access, these are the basics of multithreading programming. Trying to write multithreaded code without fully understanding this is only going to cause you troubles ;)
Title: Re: Non-Locked threads and Locked Threads
Post by: FleshyOverlord on January 26, 2020, 03:21:45 pm
Thank you for the help!
Title: Re: Non-Locked threads and Locked Threads
Post by: Nexus on January 30, 2020, 05:54:26 pm
Also, since C++11 we have threading functionality in the standard library.

After learning general multithreading concepts, you may want to have a look at it:
https://en.cppreference.com/w/cpp/thread