11
b3b3
7y

I'm writing a multi threaded program right now and just pray for the threads not accessing my var at the same time :) but I cannot use a locking algo because my 1st thread needs to access that var up to 1000 times a second. Pray for it to work as it should 🤔😇

Comments
  • 8
    The race condition is strong in this code
  • 0
    Semaphores are your friend.
  • 1
    @soolkiki Is it a lock guard? I heard of semaphores in the Vulkan API. As I said I cannot restrict the access to my var since my thread 1 needs to access it the whole time. If it cannot access it it won't work as it should. I'll try it though
  • 0
    @b3b3 more of a mechanism in which allows threads to share information. Think of how operating systems multitask. Semaphores are what allow them to do what they do.

    I think I understood you wanted to share the variable between threads, well, semaphores would allow you to either lock or unlock that variable based on conditions you define.
  • 0
    Semaphores are literally everywhere and can get complex.
  • 1
    *never use global variables* just saying
  • 2
    @linuxer4fun
    Before I learned how to share info between threads using queues, this is what I did.
    It resulted in some horror stories.
  • 2
    @soolkiki youre saved now... A few weeks ago, i wanted to multithread a C programm. Queues dont really exist for it (atleast i didnt find anything like that) i cried in the evening (no shit, sherlock)
  • 1
    @linuxer4fun oh geez...yeah, I'm not aware of any in c, but I imagine you'd be building your own queue.

    I feel bad for you!
Add Comment