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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:33:09+00:00 2026-06-03T05:33:09+00:00

Right now I’m working on my project and I have a question about initialization

  • 0

Right now I’m working on my project and I have a question about initialization of semaphores. Actually I’m programming on Mac OS X, but I tried to compile me project on Linux and it doesn’t compile. On OS X it compiles but every time just crashing at the moment of initialization.

sem_t *mutex_1, *mutex_2, *mutex_3, *reader, *writer;

int initialization_semaphores (void) 
{
    int ERROR = EOK;
    if ((mutex_1 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
        ERROR = ESEM;
    if ((mutex_2 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
        ERROR = ESEM;
    if ((mutex_3 = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
        ERROR = ESEM;
    if ((reader = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
        ERROR = ESEM;
    if ((writer = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, 0, 0)) == MAP_FAILED)
        ERROR = ESEM;

    if (ERROR == EOK) {
        if (sem_init(mutex_1, 1, 1) == -1)
            ERROR = ESEM;
        if (sem_init(mutex_2, 1, 1) == -1)
            ERROR = ESEM;
        if (sem_init(mutex_3, 1, 1) == -1)
            ERROR = ESEM;
        if (sem_init(reader, 1, 1) == -1)
            ERROR = ESEM;
        if (sem_init(writer, 1, 1) == -1)
            ERROR = ESEM;
    }
}

When I tried to compile it on linux I see this:

/tmp/ccmkN9G7.o: In function `initialization_semaphores':
readerWriter.c:(.text+0x1a2): undefined reference to `sem_init'
readerWriter.c:(.text+0x1cb): undefined reference to `sem_init'
readerWriter.c:(.text+0x1f4): undefined reference to `sem_init'
readerWriter.c:(.text+0x21d): undefined reference to `sem_init'
readerWriter.c:(.text+0x246): undefined reference to `sem_init'
readerWriter.c:(.text+0x275): undefined reference to `shm_open'

Is it right? :

int ERROR = EOK;
mutex_1 = sem_open("mutex1", O_CREAT, S_IRUSR | S_IWUSR, 1);   
mutex_2 = sem_open("mutex2", O_CREAT, S_IRUSR | S_IWUSR, 1);  
mutex_3 = sem_open("mutex3", O_CREAT, S_IRUSR | S_IWUSR, 1); 
reader = sem_open("reader", O_CREAT, S_IRUSR | S_IWUSR, 1); 
writer = sem_open("writer", O_CREAT, S_IRUSR | S_IWUSR, 1);   
  • 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-03T05:33:10+00:00Added an answer on June 3, 2026 at 5:33 am

    Mac OSX is non-conformant and does not support sem_init. The function exists but it silently fails or worse, leaving you with a non-working semaphore.

    I’d encourage you to file a bug with Apple, since this is a real, long-standing problem that’s affecting application portability badly. The more people who complain, the more hope there is of getting it fixed.

    As for working around it, you can try to find/write a replacement implementation of all the POSIX semaphore functions and link your program to that, or you could switch to using sem_open instead of mmap and sem_init.

    (As long as you’re already going through the overhead of mapping a whole page for each semaphore, sem_open doesn’t really cost you anything more. Where this bug is really a show-stopper is when you want to include your semaphores inside an existing struct.)

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

Sidebar

Related Questions

Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I am working on c# windows applications developement. But my concern is
Right now I'm making an extremely simple website- about 5 pages. Question is if
right now I have this pulling data for the current week, but the week
Right now, I'm making Dungeon Master like game. The game have to be more
Right now I have an SSIS package that runs every morning and gives me
Right now, I have three models Post, Comment and User (using Devise ) associated
Right now, I have a domain entity named StyleBundle. This StyleBundle takes a list
right now i have this <script type='text/javascript'> $(#beau).click(function(){ $(#beau).animate({margin-Top: 738px}, fast); }); </script> and
Right now any new UIViewController added to my storyboard needs to have a class

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.