tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Strange semaphore behavior, sem_init() fails with errno 4294967295 (-1)



Mouse a écrit :
>> In each thread, my software does a fork() followed by an execve().
>> If I remove this fork(), I'm unable to reproduce this bug.
> 
> I have a fuzzy memory that fork() may do something to semaphores...?

	Maybe if fork() occurs just when sem_init() tries to allocate memory
for example ? It's only a supposition.

>> int
>> sem_init(sem_t *sem, int pshared, unsigned int value)
>> {
>>     intptr_t    semid;
>>     int error;
>>
>>     if (_ksem_init(value, &semid) == -1)
>>         return (-1);
>>
>>     if ((error = sem_alloc(value, semid, sem)) != 0) {
>>         _ksem_destroy(semid);
>>         errno = error;
>>         return (-1);
>>     }
>>
>>     return (0);
>> }
> 
>> As errno contains an error, I suppose that sem_alloc() returns this
>> error, but sem_alloc() can only return ENOSPC or EINVAL...
> 
> If _ksem_init is, as the name seems to imply, a kernel call, could it
> maybe be setting errno?
> 
> What is your basis for saying that sem_alloc can generate only ENOSPC
> and EINVAL?  Reading the source, or looking at documentation, or what?

	Reading the source.

	Best regards,

	JKB


Home | Main Index | Thread Index | Old Index