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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:34:52+00:00 2026-06-07T00:34:52+00:00

The following is pseudo code of an integration test that is failing: [Test] void

  • 0

The following is pseudo code of an integration test that is failing:

[Test]

void TestLogger()
    // Init static logger
    Logger.Init(pathToFile);

    // Create five threads that will call LogMessages delegate
    for i = 1 to 5 
    {
       Thread aThread = new Thread(LogMessages)
       aThread.Start(i);
    }

    // let threads complete their work
    Thread.Sleep(30000);

    /// read from log file and count the lines
    int lineCount = GetLineCount();

    // 5 threads, each logs 5 times = 25 lines in the log
    Assert.Equal(25, lineCount);


static void LogMessages( object data )
  // each thread will log five messages
  for i = 1 to 5 
  Logger.LogMessage(i.ToString() + " " + DateTime.Now.Ticks.ToString());
  Thread.Sleep(50);

The number of lines seem to change each time the test is run. Sometimes the number of lines is 23 and sometimes 25.

After I dug through the code a little bit, I noticed that the log file is getting accessed at the same time by multiple threads (verified by tick count being the same). There is no lock around the access to this file, but at the same time I see no exceptions being thrown. Can anyone explain why the log line count between runs is inconsistent? Furthermore, is this a negative effect of writing to the same file by multiple threads at the same time?

  • 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-06-07T00:34:53+00:00Added an answer on June 7, 2026 at 12:34 am

    Race conditions, as you have here, are notoriously unpredictable. You never know how many writes won’t work properly – it might even work completeely fine, sometimes. And yes, this is a negative effect of writing to the same file from multiple threads without synchronization.

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

Sidebar

Related Questions

i have following pseudo code : void siftup(int n) pre condition n>0 && heap(1,n-1)
I was given the following pseudo code in order to get the form that
I have the following pseudo code that works: KeyBindings[Keys.Right] += Method1; KeyBindings[Keys.Right] += Method2;
Please take a look on the following pseudo-code: boolean blocked[2]; int turn; void P(int
How could I write a while loop that said the following (pseudo code): While
I have a button click event handler with the following pseudo code: private void
The following (pseudo-) code induces some behaviour which I dont understand. I have 2
I am currently working with the following pseudo code block to fix a regex
I think I might need to do something like the following pseudo-code in my
I can drop a SqlServer Backup Device using SQL-DMO using the following pseudo-code: SQLDMO.SQLServer2

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.