Getting the value of a semaphore

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024

Комментарии • 10

  • @virendrakumarmishra876
    @virendrakumarmishra876 3 года назад +7

    I'm following you for last few weeks you are really best mentor i have ever come across❤️

  • @narasarajv5278
    @narasarajv5278 3 года назад +1

    Thank you

  • @pulkitjoshi6196
    @pulkitjoshi6196 3 года назад +2

    Is skipping a critical section depending upon the semaphore value ok thing to do ? Also if not, than is there other way to do it?

    • @pulkitjoshi6196
      @pulkitjoshi6196 3 года назад

      I am in a situation where I have to use only a single thread. Now I have to take a semaphore "token" , decrease using other thread. While at the same time if any request arrives at token_request , I want to process it too. Now if the semaphore "token" get to 0 value, I will not be able to accept the token_requests, so I want to skip critical section within "token" as well as within "token_request", if a condition holds.

    • @CodeVault
      @CodeVault  3 года назад

      If you have just one thread... I'm not sure why you need semaphores

    • @pulkitjoshi6196
      @pulkitjoshi6196 3 года назад

      @@CodeVault Oh sorry, I meant for a particular functionality I use a single thread. In total there are 3 types of thread. 2 types can be of any count while last one (the one I told about above) will be only single thread that will access the semaphores.

  • @ASHISHBHAGAT-h1h
    @ASHISHBHAGAT-h1h Год назад

    Can you please make the video on how to setup vs code for multi-threading program?

    • @CodeVault
      @CodeVault  Год назад

      It's not much different than what I show in the video here: ruclips.net/video/9pjBseGfEPU/видео.html
      You only have to change in tasks.json the args property to have -pthread, like so:
      "args": [
      "-g",
      "${file}",
      "example.c",
      "-pthread"
      "-o",
      "${fileDirname}/bin/${fileBasenameNoExtension}"
      ],

    • @ashishbhagat7974
      @ashishbhagat7974 Год назад

      @@CodeVault is it same for windows also?

    • @CodeVault
      @CodeVault  Год назад +1

      @@ashishbhagat7974 pthreads are part of the Unix API, so Windows doesn't have this library. You will have to use something like WSL (or just switch to Linux) to use pthreads