Sem_post() fail with valid semaphore?

Any number of things. Something else could be destroying the semaphore or overwriting the memory used to store it or the pointer to it. Another possibility is that you're calling sem_post() too many times and the counter overflows.

A code sample would help.

I am experiencing the same problem and I don't know what could be happening. I've checked that the counter doesn't overflow and the memory is correct, but what is more strange is that sem_post returns -1 but the counter inside is correctly increased... – David Alfonso Oct 19 '10 at 10:49.

We had the same problem, and after a long time figuring out what could be happening, we discovered that the problem occurred because the semaphore was defined inside a struct that had its byte alignment changed to 1 (in this case using the pragma pack(1) directive). The POSIX semaphores implementation on Linux uses the futex syscall. According to the futex man page, EINVAL is returned when "An operation was not defined or error in page alignment."

In our case, either removing the pragma pack(1) directive or defining the semaphore as the first element of the struct, solved the problem.

1 for a great example of why packed structures should never be used. – R.. Aug 4 at 6:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions