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

  • Home
  • SEARCH
  • 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 145793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:29:12+00:00 2026-05-11T08:29:12+00:00

I have multiple asp.net web apps serving a set of files. Periodically, one will

  • 0

I have multiple asp.net web apps serving a set of files. Periodically, one will update the file before serving it, but it can’t update the file if it is in use.

I could solve this issue by using a named mutex where the name is the file path (replacing the invalid characters of course). I’ve used this in other situations, but you can see how inefficient it is. Only one process will be able to serve the file at a time.

A reader/writer lock would be perfect, but they are designed to work within a single process. Plus I’d have to create a reader/writer lock for every file that might get updated, and there are a lot.

What I really need is a reader/writer lock that can be named like a mutex. Is there such a thing? Or can such a thing be created using the existing locks?

  • 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. 2026-05-11T08:29:13+00:00Added an answer on May 11, 2026 at 8:29 am

    It’s possible to simulate a reader/writer lock using a Mutex and a Semaphore. I wouldn’t do it if I had to access it thousands of times per second, but for dozens or perhaps hundreds of times per second, it should work just fine.

    This lock would allow exclusive access by 1 writer or concurrent access by N (possibly large, but you have to define it) readers.

    Here’s how it works. I’ll use 10 readers as an example.

    Initialize a named Mutex, initially unsignaled, and a named Semaphore with 10 slots:

      Mutex m = new Mutex(false, 'MyMutex');   Semaphore s = new Semaphore(10, 10, 'MySemaphore'); 

    Acquire reader lock:

    // Lock access to the semaphore. m.WaitOne(); // Wait for a semaphore slot. s.WaitOne(); // Release mutex so others can access the semaphore. m.ReleaseMutex(); 

    Release reader lock:

    s.Release(); 

    Acquire writer lock:

    // Lock access to the seamphore m.WaitOne(); // Here we're waiting for the semaphore to get full, // meaning that there aren't any more readers accessing. // The only way to get the count is to call Release. // So we wait, then immediately release. // Release returns the previous count. // Since we know that access to the semaphore is locked // (i.e. nobody can get a slot), we know that when count // goes to 9 (one less than the total possible), all the readers // are done. s.WaitOne(); int count = s.Release(); while (count != 9) {     // sleep briefly so other processes get a chance.     // You might want to tweak this value.  Sleep(1) might be okay.     Thread.Sleep(10);     s.WaitOne();     count = s.Release(); }  // At this point, there are no more readers. 

    Release writer lock:

    m.ReleaseMutex(); 

    Although fragile (every process using this better have the same number for the semaphore count!), I think it will do what you want as long as you don’t try to hit it too hard.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer datetime.combine is complaining because it expects the second argument to… May 11, 2026 at 10:54 am
  • added an answer Short Answer Use a queue as a finite buffer, processed… May 11, 2026 at 10:54 am
  • added an answer I read something somewhat detailed about this once and I… May 11, 2026 at 10:54 am

Related Questions

There are multiple values I have been storing in ASP.NET configSections sections for each
I am building a site in asp.net and have multiple subdomains. For example, one.cookies.com
I have multiple selects: <select id=one> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> <select
I have multiple projects in a couple of different workspaces. However, it seems like
I have multiple classes that all derive from a base class, now some of
I have multiple layers in an application and i find myself having to bubble
I have multiple threads (C# application running on IIS) running that all need to
I have multiple branches of a project checked out, each under their own directory
I have multiple logos of various companies in various formats that needs to be
I have multiple processes monitoring an MSMQ queue. I want to do multi-step operations

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.