[fpc-devel] Why FreeBSD sem_init() works different to Linux?

Graeme Geldenhuys graeme at geldenhuys.co.uk
Mon Feb 4 12:47:48 CET 2013


Hi,

I found another problem with Semaphores between FreeBSD and Linux.

Attached is my test project. Again, it is similar code used in tiOPF.

For some reason under FreeBSD, it *always* zeros the variable that holds
the Max Pool Size value passed in to sem_init()'s third parameter. This
means that if I try and us that variable anywhere after the sem_init()
call, like when I want to destroy the semaphore, I can't because the
variable now holds the value 0.

Here is an example of the test program's output. Not the value of
FMaxPoolSize before and after sem_init() call. Also note the value of i
- no destruction code (sem_post) is executed.

---------[ output under Linux ]---------------
$ ./project1
FMaxPoolSize before = 2
FMaxPoolSize after = 0
c = 2
Now create a lock
c = 1
Now create a lock
c = 0
i = 0
-----------------------------------------------

And here is that exact same test project under Linux. Note the
FMaxPoolSize variable still has the original value after the sem_init()
call - as expected. Also the i variable increments as we unlock the
semaphore.


---------[ output under Linux ]---------------
$ ./project1
FMaxPoolSize before = 2
FMaxPoolSize after = 2
c = 2
Now create a lock
c = 1
Now create a lock
c = 0
i = 0
unlock a semaphore
i = 1
unlock a semaphore
i = 2
-----------------------------------------------


Any idea why FreeBSD does this? A bug in FPC+FreeBSD?


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: semp_test.tar.gz
Type: application/x-gzip
Size: 1618 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130204/016a8382/attachment.bin>


More information about the fpc-devel mailing list