Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Non-Locked threads and Locked Threads  (Read 483 times)

0 Members and 1 Guest are viewing this topic.

FleshyOverlord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Non-Locked threads and Locked Threads
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32233
    • View Profile
    • SFML's website
    • Email
Re: Non-Locked threads and Locked Threads
« Reply #1 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 ;)
Laurent Gomila - SFML developer

FleshyOverlord

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Non-Locked threads and Locked Threads
« Reply #2 on: January 26, 2020, 03:21:45 pm »
Thank you for the help!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6208
  • Thor Developer
    • View Profile
    • Bromeon
Re: Non-Locked threads and Locked Threads
« Reply #3 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
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book