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 6673047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:54+00:00 2026-05-26T03:34:54+00:00

I am writing a small agent-based interaction simulation in a discrete simulator and am

  • 0

I am writing a small agent-based interaction simulation in a discrete simulator and am beginning to write some code that looks like the following. I have not some event-driven programming before but did not really observe this situation. I am wondering if the following piece of code will lead to a race condition while updating the value of msgRcvd.

// Following is the event-loop per-se
Controller {
    if (...) {
       SendMessage(currentTime() + 5, i,j)
       SendMessage(currentTime() + 5, i,k)
    }
    print currentTime(), msgsRcvd
    Schedule(currentTime()+1, Controller)
}

// The following function is called when an 
// agent receives a message
Receive(Agent agent) {
    if (...) {
       msgsRcvd++ // <-- this is a global variable
    }
}

My understanding is that at currentTime() + 5 both the agents receive the message at the same time because both the events are happening at the same logical time so I should see the number of messages to be 2? Or will I see some strange race condition happening and the value is dependent on the scheduler (i.e. it could end up printing 1 or 2)? Any suggestions?

  • 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-26T03:34:54+00:00Added an answer on May 26, 2026 at 3:34 am

    The answer depends on the implementation of your event transport and is not language agnostic in that sense.

    In all systems I have worked with, each message would be placed separately into an event queue and the receiving agent would take events off of that queue in order. Assuming you have one thread generating messages and one event taking messages off of the queue, I don’t see an opportunity for a race condition.

    If your event queue has some intelligence that attempts to consolidate events based on the timestamp, you would only see one event in the receiving agent. I’m not aware of a common system that does that (though some UI systems may for example consolidate two rapid mouse clicks to a double click… but that’s specific behavior of a specific event system and not language/platform agnostic).

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

Sidebar

Related Questions

I'm writing a small agent in java that will play a game against other
I'm writing a small application in VB.NET and I would like some of the
when writing small functions I often have the case that some parameters are given
I'm writing a small library where I'm writing some interfaces that takes a MailMessage
I'm writing a small read-only FTP-like server. Client says give me that file and
While writing a small paint-like application (for myself), I originally had the following code
Coming from a PHP background, I'm used to writing small functions that return a
I am writing a small console application in C# that references a custom assembly
I am currently writing a small application with Python (3.1), and like a good
While writing a small C# application for myself I realized that it would be

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.