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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:06:57+00:00 2026-05-28T01:06:57+00:00

I am designing a new improved Logger component (.NET 3.5, C#). I would like

  • 0

I am designing a new improved Logger component (.NET 3.5, C#).

I would like to use a lock-free implementation.

Logging events will be sent from (potentially) multiple threads, although only a single thread will do the actual output to file/other storage medium.

In essence, all the writers are * enqueuing* their data into some queue, to be retrieves by some other process (LogFileWriter).

Can this be achieved in a lock-less manner? i could not find a direct reference to this particular problem on the net.

  • 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-28T01:06:58+00:00Added an answer on May 28, 2026 at 1:06 am

    If you find that using a lock in this case is too slow, you have a much bigger problem. A lock, when it’s not contended, takes about 75 nanoseconds on my system (2.0 GHz Core 2 Quad). When it’s contended, of course, it’s going to take somewhat longer. But since the lock is just protecting a call to Enqueue or Dequeue, it’s unlikely that the total time for a log write will be much more than that 75 nanoseconds.

    If the lock is a problem–that is, if you find your threads lining up behind that lock and causing noticeable slowdowns in your application–then it’s unlikely that making a lock-free queue is going to help much. Why? Because if you’re really writing that much to the log, your lock-free blocking queue is going to fill up so fast you’ll be limited to the speed of the I/O subsystem.

    I have a multi-threaded application that writes on the order of 200 log entries a second to a Queue<string> that’s protected by a simple lock. I’ve never noticed any significant lock contention, and processing isn’t slowed in the least bit. That 75 ns is dwarfed by the time it takes to do everything else.

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

Sidebar

Related Questions

I am currently designing a new .NET application and would like to keep it
We are designing a new database and I would like some input in where
I'm designing a new component to a system, trying to follow the various guidelines
I am designing a new laboratory database. My primary data tables will have at
I'm in the process of designing a new database for an application. I'd like
I'm designing an application that will use Oracle , and we have this department
I'm currently about to start designing a new application. The application will allow a
Designing a new system from scratch. I'll be using the STL to store lists
When designing a new system or getting your head around someone else's code, what
While designing a new WPF application I noticed exceptions not being thrown during data

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.