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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:18:41+00:00 2026-05-28T03:18:41+00:00

I am not much into scheduling threads, i have like 4-5 threads and each

  • 0

I am not much into scheduling threads, i have like 4-5 threads and each of them will add data to one same buffer at random time.
How i can schedule the threads so there is no case two or more threads to access the buffer at same time ?
I am coding in C on Windows environment.

Thanks in advance.

  • 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-28T03:18:42+00:00Added an answer on May 28, 2026 at 3:18 am

    The shared buffer needs to be protected from concurrent reads/writes by different threads. A synchronization object should be used to prevent this from occuring. Anytime a thread wants to read from or write to the shared buffer it would acquire the lock, perform its operations on the shared buffer and release the lock once it no longers requires the buffer.

    An example synchronization object would be CriticalSection:

    static CRITICAL_SECTION shared_buffer_lock;
    static char shared_buffer[10];
    
    int main()
    {
        InitializeCriticalSection(&shared_buffer_lock);
    
        /* Start threads */
        ...
    
        /* Wait for threads */
        ...
    
        DeleteCriticalSection(&shared_buffer_lock);
    
        return 0;
    }
    
    /* In thread.. */
    
    /* Obtain sole access to 'shared_buffer' */
    EnterCriticalSection(&shared_buffer_lock);
    
    /* Use 'shared_buffer' ... */
    
    /* Release sole access of 'shared_buffer' */
    LeaveCriticalSection(&shared_buffer_lock);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not much into COM interfaces, so i have a small question, say I
So, I'm just stabbing into the wild. I'm really not much of a data-miner.
I'm sorry for this very newbish question, I'm not much given into web development.
I've not gone into much research here, but the intuitive thing is not working:
I'm not much into audio engineering, so please be easy on me. I'm receiving
I have not touched ASP in almost ten years and I am not much
I often times have the need to import 3D points (x,y,z data) into the
I have a very simple query that is not much more complicated than: select
I am not much into gaming but i am learning and doing some practicles
I'm probably reading too much into ignore, but other than not showing up in

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.