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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:26:51+00:00 2026-05-17T02:26:51+00:00

I need to do some process synchronization in C. I want to use a

  • 0

I need to do some process synchronization in C. I want to use a monitor, and I have read a lot about them. However I have been unable to find out how to implement one in C. I have seen them done in Java and other languages like C++, but I am unable to find examples in C.

I have looked through K&R and there is no example in there. I skimmed through Unix Systems Programming, Communication, Concurrency and Threads, but was unable to find a monitor implementation in there.

This brings me here. Where and how do I define a monitor? How do I implement it within the rest of the code?

/* I am coding in a *nix environment */

  • 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-17T02:26:52+00:00Added an answer on May 17, 2026 at 2:26 am

    I did this recently for a project, the concept I implemented was to have one thread start all of the others and then use semaphores and mutexes to control the inter process sync issues while dealing with shared memory.

    The concept of a monitor, in the context of the monitor design pattern, is a construct that is basically there to hide mutual exclusion. This concept is expressed in C++ Boost but it doesn’t exist in core C++ or C. The way you handle this type of job in C is with good old fashioned mutexes (binary semaphores) and semaphores. You can read more about this here.

    Below is a basic way to initialize a semaphore and mutex, you may need to do more research of your own, but here is a link to get you started.

    pthread_mutex_t myMutex;
    sem_t mySemaphore;
    int status;
        status = pthread_mutex_init(&myMutex, NULL);
        if(status != 0)
            exit_with_error("There was an Error Initalizing the Mutex\n");
        status = sem_init(&mySemaphore, 0, 0);
        if(status != 0)
            printf("There was an Error Initalizing the Semaphore\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do some process injection using C++ but I would prefer to
I need some info on how to use margins and how exactly padding works.
I need some help from the shell-script gurus out there. I have a .txt
I need some information about localization. I am using .net 2.0 with C# 2.0
I need some advice as to how I easily can separate test runs for
I need some software to explore and modify some SQLite databases. Does anything similar
We need some input on what is a good design pattern on using AJAX
I need some sort of interactive chart control for my .NET-based web app. I
I need some basic CMS functionality with rich text editing. On stack overflow there
I need some pointers on how to detect unknown hardware using .NET and C++/C#.

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.