[fpc-pascal] Re: Semaphore problems
graemeg.lists at gmail.com
Mon Jul 24 12:21:36 CEST 2006
Looking at my code, I might have initialized my semaphore incorrectly.
The Windows portion works, and I tried to port it to Linux as follows...
if FSemaphore <> 0 then
CloseHandle( FSemaphore ) ;
FSemaphore := CreateSemaphore( nil, FiMaxPoolSize, FiMaxPoolSize, nil );
sem_destroy( FSemaphore );
if sem_init(FSemaphore, 0, 1) <> 0 then
raise Exception.Create('Failed to create the semaphore');
On 7/24/06, Graeme Geldenhuys <graemeg.lists at gmail.com> wrote:
> I am having troubles with porting Semaphores in a project under Linux.
> Under Windows everything works fine, but under Linux my app keeps
> The project is tiOPF v2 (TechInsite Object Persistent Framework).
> There is a class called TtiPool, that handles a pool of database
> When I run the Unit Tests and create a single Lock and the Unlock it,
> all works fine. If I then iterrate that test by creating 10 locks and
> then call unlock 10 times, the Unit Tests freeze on the following line
> with the second iteration:
> if sem_wait(FSemaphore) <> 0 then
> raise EtiOPFInternalException.Create(cErrorTimedOutWaitingForSemaphore);
> * Under Linux, I am using the "pthreads" unit. What is the difference
> between the cthreads and pthreads unit?
> * The calls I am using from pthreads are:
> * sem_init() to create a semaphore
> * sem_wait() to lock the semaphore
> * sem_post() to unlock the semaphore
> All the above with a variable of type TSemaphore.
> Now, I have to admit, I don't know much about Semaphore's... Anybody
> know of some good documentation or tutorial on the net?
> Anything obvious I could be doing wrong?
> There's no place like 127.0.0.1
There's no place like 127.0.0.1
More information about the fpc-pascal