Tuesday, October 16, 2012

OS X: don't trust the POSIX certificate

According to Wikipedia as well as other sources, Apple's OS X is supposed to be 100% POSIX (Portable Operating System Interface) compliant. Please don't trust them – they are wrong (or at least have another measure for 100%).
I already knew that OS X as well as most Apple products are different – sometimes "good different", sometimes "bad different". This time, OS X is definitely bad different.

As you probably know, IEEE's POSIX is a family of standards for maintaining compatibility between operating systems. It defined a really powerful API and most variants of UNIX as well as other operating systems (e.g. OS X, QNX and most Linux distributions) are compatible with those APIs.
Maybe this is already the problem: POSIX only defines the application programming interface but apparently doesn't require an implementation.

Now what is the problem I have? I'm supposed to solve a small assignment for my university course Distributed Real-Time Systems. The topic is JNI (Java Native Interface) and how to start a JVM (Java Virtual Machine) from C and then communicate between the Java- and C-code.
Because it's supposed to use multiple threads to enforcing real-time (like) execution, I wanted to communicate between the manager- and real-time-thread using semaphores. The real-time thread just posts (sem_post) whenever it changed values, the manager has to send to Java.
Of course, unnamed semaphores via sem_init are sufficient for that, no IPC (Inter Process Communication) is needed.

The problem: sem_init just wouldn't stop resulting in -1, which, of course, stands for an error. Now the weird thing was, that the error said, that the function is not implemented. Why wouldn't it be implemented? It's defined in the header file and it compiles without a problem.
So I consulted friend Google and what do I find? Apparently OS X does comply to the POSIX semaphore interface description, but does not implement all the functions. And one of those functions is sem_init.
Apparently Apple thinks, developers should use named semaphores instead, because there's no difference in those functions.

What do we learn from this?

  1. Always check return error codes in C,
  2. OS X is definitely not fully POSIX compliant and
  3. again, always check return error codes in C ;)

Labels: , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home