Am 16.02.2012 17:04, schrieb Antonio Fortuny:
Hi all.

On an OpenSuse 12.1, Lazarus 0.9.31, FPC 2.4.4 I can't create a semaphore
Code:

LockerS: Integer;
SemKey: Integer;


SemKey := strToIntDef(ESemaphoreKey.Text, -1);
if SemKey = -1 then
Break;
LockerS := semget(SemKey, 1, 0666 + IPC_CREAT + IPC_EXCL);
if LockerS >= 0 then begin
// got the semaphore: initialize it
Args.Val := 1;
Ret := semctl(LockerS, 0, SEM_SETVAL, Args);
if Ret >= 0 then begin
// semaphore locked; get out
Operation.sem_op := -1; //reduce the semaphore count to lock
Operation.sem_num := 0; //signifies 0th semaphore
Operation.sem_flg := IPC_EXCL; // fail if key exists
Ret := semop(LockerS, @Operation,1);
if Ret >= 0 then
Break;
end
end else begin
LastError := errno;
LastErrorText := strerror(LastError);
Memo1.Lines.Add(Format('semaphore locker not created errno:%d-%s',
[LastError, LastErrorText]));
end

*semget *always returns -1 with errno set to 2 (?) whatever the contents
of *SemKey* could be.

What is wrong ?

According to http://pubs.opengroup.org/onlinepubs/7908799/xsh/semget.html error 2 means the following:

[ENOENT]
A semaphore identifier does not exist for the argument key and (semflg&IPC_CREAT) is equal to 0.

Can you try to use "or" instead of "+"? Also you're trying to pass a C style octal number. Replace the leading zero by a "&" which is the equivalent declaration for Free Pascal (see also here: http://www.freepascal.org/docs-html/ref/refse6.html ).

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to