Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7004139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:09:38+00:00 2026-05-27T21:09:38+00:00

This is psuedocode for task synchronization using a semaphore. The operation involves a security

  • 0

This is psuedocode for task synchronization using a semaphore.
The operation involves a security check between transferring data.

Begin_Security_Check=create_semaphore(0);
Security_Check_Done=create_semaphore(0);

Task Security_Check
{
    while(true)
    {
        wait_semaphore(Begin_Security_Check);
          (*actions check data*)
        signal_semaphore(Security_Check_Done);
    }
}

Task Download_Data;
{
      (*actions to download data from WAN to router buffer*)
    signal_semaphore(Begin_Security_Check);

    wait_semaphore(Security_Check_Done);
      (*actions to download data from router buffer to LAN*)
}

In the notes I’m reading :

s= create_semaphore(v);
Where v=0 or 1

wait_semaphore(s);
If s=1 then set s=0 and allow the calling task to proceed, otherwise suspend the calling task.

signal_semaphore(s);
If there is no task waiting for semaphore sthen set s=1 otherwise resume any task that is waiting on semaphore s.


But this means wait_semaphore(Begin_Security_Check); has a value of 0 because Begin_Security_Check=create_semaphore(0);, right? This means it should suspend the calling task ?
The first two definitions have create_semaphore(0); — that means they’re both the same?

I’m really confused, can someone please go step by step and explain how this pseudo code is running?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:09:39+00:00Added an answer on May 27, 2026 at 9:09 pm

    Initially we create two semaphores, each with a value of 0.

    Now I’m guessing these two Tasks are somehow started on separate threads – in particular, Task Security_Check seems to loop forever, so it must be sitting in its own thread waiting for work. When it calls wait_semaphore(Begin_Security_Check);, it will pause until someone signals Begin_Security_Check.

    Now someone calls Download_Data. It does whatever it needs to do to download the data, and then signals the semaphore Begin_Security_Check. This wakes up the Security_Check thread, which then proceeds to do whatever it needs to do and signals the Security_Check_Done semaphore. Meanwhile, the downloading thread will have gone on to wait_semaphore(Security_Check_Done);, causing it to pause until the Task Security_Check signals that semaphore. So it will not proceed until the security check is finished.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a lot of trouble with this task. Using the Wikipedia definition
I'm developing an asp.net (classic) application trying to implement the MVP pattern using this
Suppose I have a function that performs some task (this is in Python pseudocode):
I need to do something similar to the task described in this question: Construct
So I want to automate a manual task using shell scripting, but I'm a
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today
This might seem like a stupid question I admit. But I'm in a small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.