Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 3:47 PM, Jonas Maebe a écrit : On 12 Feb 2008, at 15:43, Damien Gerard wrote: Ok thanks ! I ve got all I need to use Semaphore, except one thing : How I set the limit ? I mean I want to restrict to 4 concurrent accesses to a shared ressource. With pthread I have int se

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Jonas Maebe
On 12 Feb 2008, at 15:43, Damien Gerard wrote: Ok thanks ! I ve got all I need to use Semaphore, except one thing : How I set the limit ? I mean I want to restrict to 4 concurrent accesses to a shared ressource. With pthread I have int sem_init(sem_t *sem, int pshared, unsigned int value);

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 3:08 PM, Jonas Maebe a écrit : On 12 Feb 2008, at 14:55, Damien Gerard wrote: I though that too but currenttm can not be found under Windows. What is the good unit for it ? Indeed, you shouldn't use currenttm. Use this routine instead (from the system unit, the result

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Graeme Geldenhuys
On 12/02/2008, Jonas Maebe <[EMAIL PROTECTED]> wrote: > > CurrentTM.Semaphore* should also work under Windows (if it doesn't, > please file a bug report). And the way to use those is by calling > > {$ifdef unix} > uses >cthreads; > {$endif} > var >p: pointer; > begin >p:=currenttm.Semap

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Jonas Maebe
On 12 Feb 2008, at 14:55, Damien Gerard wrote: I though that too but currenttm can not be found under Windows. What is the good unit for it ? Indeed, you shouldn't use currenttm. Use this routine instead (from the system unit, the result indicates success or failure): Function GetThreadM

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Jonas Maebe
On 12 Feb 2008, at 14:54, Damien Gerard wrote: Le Feb 12, 2008 à 2:44 PM, Jonas Maebe a écrit : No, you can't, because sem_init does not exist on Mac OS X. Use the RTL implementation, it works on all platforms. Further, the above code looks buggy because it always calls sem_destroy for F

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 2:41 PM, Jonas Maebe a écrit : On 11 Feb 2008, at 10:45, Damien Gerard wrote: I think it has been discussed before but I would like to use Semaphores, to allow multiple reads but 1 write at once (which is in fact commons operations in a multi-thread program). My progra

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 2:44 PM, Jonas Maebe a écrit : On 12 Feb 2008, at 14:20, Damien Gerard wrote: Le Feb 12, 2008 à 12:36 PM, Graeme Geldenhuys a écrit : procedure TtiPool.CreatePoolSemaphore; begin {$IFDEF MSWINDOWS} if FSemaphore <> 0 then CloseHandle(FSemaphore); FSemaphore := CreateSema

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Jonas Maebe
On 12 Feb 2008, at 14:20, Damien Gerard wrote: Le Feb 12, 2008 à 12:36 PM, Graeme Geldenhuys a écrit : procedure TtiPool.CreatePoolSemaphore; begin {$IFDEF MSWINDOWS} if FSemaphore <> 0 then CloseHandle(FSemaphore); FSemaphore := CreateSemaphore(nil, FMaxPoolSize, FMaxPoolSize, nil); {$ENDI

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Jonas Maebe
On 11 Feb 2008, at 10:45, Damien Gerard wrote: I think it has been discussed before but I would like to use Semaphores, to allow multiple reads but 1 write at once (which is in fact commons operations in a multi-thread program). My program must work under OSX/Nux and Windows. I may have mi

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 12:36 PM, Graeme Geldenhuys a écrit : On 11/02/2008, Damien Gerard <[EMAIL PROTECTED]> wrote: My program must work under OSX/Nux and Windows. I may have missed something but I can not find something suitable for me. Under Windows OpenSemaphore, under unixes CurrentTM.Semaphor

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Damien Gerard
Le Feb 12, 2008 à 12:36 PM, Graeme Geldenhuys a écrit : On 11/02/2008, Damien Gerard <[EMAIL PROTECTED]> wrote: My program must work under OSX/Nux and Windows. I may have missed something but I can not find something suitable for me. Under Windows OpenSemaphore, under unixes CurrentTM.Semaphor

Re: [fpc-pascal] Semaphore

2008-02-12 Thread Graeme Geldenhuys
On 11/02/2008, Damien Gerard <[EMAIL PROTECTED]> wrote: > My program must work under OSX/Nux and Windows. > I may have missed something but I can not find something suitable for > me. > Under Windows OpenSemaphore, under unixes CurrentTM.Semaphore*... > > Is there any TSemaphore class of equivalent

[fpc-pascal] Semaphore

2008-02-11 Thread Damien Gerard
Hi ! I think it has been discussed before but I would like to use Semaphores, to allow multiple reads but 1 write at once (which is in fact commons operations in a multi-thread program). My program must work under OSX/Nux and Windows. I may have missed something but I can not find something

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Vinzent Hoefler
On Tuesday 25 July 2006 14:51, Micha Nelissen wrote: > Vinzent Hoefler wrote: > > Ok, there's a glitch: The read and write of self.ThreadId is > > required to be atomic, so that a thread entering may either see "0" > > or the owner's thread id when checking, otherwise it could be > > possible, it s

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Micha Nelissen
Vinzent Hoefler wrote: > Ok, there's a glitch: The read and write of self.ThreadId is required to > be atomic, so that a thread entering may either see "0" or the owner's > thread id when checking, otherwise it could be possible, it sees its > own thread_id due to a partial update and *then* it

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Burkhard Carstens
Am Dienstag, 25. Juli 2006 11:59 schrieb Vinzent Hoefler: > On Tuesday 25 July 2006 09:04, Burkhard Carstens wrote: > > Am Dienstag, 25. Juli 2006 10:46 schrieb Micha Nelissen: > > > function Recursive_Mutex.Lock:...; > > > begin > > >// Owned by current thread? > > >if CurrentThreadId <> s

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Vinzent Hoefler
On Tuesday 25 July 2006 08:46, Micha Nelissen wrote: > Vinzent Hoefler wrote: > >> Ehm, no. > > > > Ehm, yes. I was being ironic here. Of course, the action of > > checking the counter and locking/unlocking the associated mutex > > must be atomic. > > But here they are not associated, they're prote

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Vinzent Hoefler
On Tuesday 25 July 2006 09:04, Burkhard Carstens wrote: > Am Dienstag, 25. Juli 2006 10:46 schrieb Micha Nelissen: > > > function Recursive_Mutex.Lock:...; > > begin > >// Owned by current thread? > >if CurrentThreadId <> self.ThreadId then > >begin > > result := pthread_mutex_loc

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Burkhard Carstens
[...] coffee, pencil and stuff ;-) off course, the local procedure "internalEnter" in Leave is a copy'n'paste rubbish. Just remove .. TCriticalSection.Leave; begin internal.lock; try if OwnerThread <> GetCurrentThreadID then begin //we are not // allowed to leave, because we don't

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Micha Nelissen
Burkhard Carstens wrote: >> I don't see the need for Owner_Check_Lock anymore ? :-) > > You have to prevent that 2 concurrent threads call lock simultanously, No, why? > so you have to take an internal lock before touching internal vars like > self.ThreadID ? No, why ? This is a common miscon

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Burkhard Carstens
Am Dienstag, 25. Juli 2006 10:46 schrieb Micha Nelissen: > Vinzent Hoefler wrote: > >> Ehm, no. > > > > Ehm, yes. I was being ironic here. Of course, the action of > > checking the counter and locking/unlocking the associated mutex > > must be atomic. > > But here they are not associated, they're p

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 23:38 schrieb Vinzent Höfler: > Vinzent Höfler wrote: > > Hmm. So we'd need a mutex inside a mutex. Now I know why they call > > it recursive. ;) So it'll be something like that: > > > > function Recursive_Mutex.Lock : ...; > > begin > >// Lock mutex inside mutex. > >

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Micha Nelissen
Vinzent Hoefler wrote: >> Ehm, no. > > Ehm, yes. I was being ironic here. Of course, the action of checking the > counter and locking/unlocking the associated mutex must be atomic. But here they are not associated, they're protected by owner_lock, as you said. >> Got confused a bit :-). Reread

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Vinzent Hoefler
On Tuesday 25 July 2006 07:46, Micha Nelissen wrote: > Vinzent Hoefler wrote: > > On Tuesday 25 July 2006 06:40, Micha Nelissen wrote: > >> Vinzent Höfler wrote: > >>> because we assume it's non-recursive, that was the whole point. > >>> So we should *first* check the count and then may lock/unlock

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Micha Nelissen
Vinzent Hoefler wrote: > On Tuesday 25 July 2006 06:40, Micha Nelissen wrote: >> Vinzent Höfler wrote: >>> because we assume it's non-recursive, that was the whole point. So >>> we should *first* check the count and then may lock/unlock the >>> mutex accordingly. >> Note that these two actions must

Re: [fpc-pascal] Semaphore problems

2006-07-25 Thread Vinzent Hoefler
On Tuesday 25 July 2006 06:40, Micha Nelissen wrote: > Vinzent Höfler wrote: > > because we assume it's non-recursive, that was the whole point. So > > we should *first* check the count and then may lock/unlock the > > mutex accordingly. > > Note that these two actions must be atomic. Oh, really?

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Micha Nelissen
Vinzent Höfler wrote: > because we assume it's non-recursive, that was the whole point. So we > should *first* check the count and then may lock/unlock the mutex > accordingly. Note that these two actions must be atomic. This is what the TryLock is for. Micha _

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 23:38 schrieb Vinzent Höfler: > Vinzent Höfler wrote: > > Hmm. So we'd need a mutex inside a mutex. Now I know why they call > > it recursive. ;) So it'll be something like that: > > > > function Recursive_Mutex.Lock : ...; > > begin > >// Lock mutex inside mutex. > >

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Vinzent Höfler wrote: Hmm. So we'd need a mutex inside a mutex. Now I know why they call it recursive. ;) So it'll be something like that: function Recursive_Mutex.Lock : ...; begin // Lock mutex inside mutex. self.Owner_Check_Lock.Lock; // Owned by current thread? if CurrentThrea

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Burkhard Carstens wrote: Am Montag, 24. Juli 2006 22:05 schrieb Vinzent Höfler: Burkhard Carstens wrote: Am Montag, 24. Juli 2006 20:33 schrieb Vinzent Höfler: Burkhard Carstens wrote: [..] btw. this is not TEvent, we are talking about, it's rtlevent .. TEvent (in synconjs) is implemented

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 22:05 schrieb Vinzent Höfler: > Burkhard Carstens wrote: > > Am Montag, 24. Juli 2006 20:33 schrieb Vinzent Höfler: > >> Burkhard Carstens wrote: > >>> [..] > >>> > ... As long as rtlevent is used with this > in mind, it should give a consistent behaviour on windo

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Micha Nelissen wrote: Vinzent Höfler wrote: Currently all I see is a subtle semantic difference between Windows- and Unix-Event's implementation. AFAICS, it's as close as it can get. You mean subtle as in, unimportant, or as in, possibly fatal ? :-) If possibly fatal, describe when/how. If u

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Burkhard Carstens wrote: Am Montag, 24. Juli 2006 20:33 schrieb Vinzent Höfler: Burkhard Carstens wrote: [..] ... As long as rtlevent is used with this in mind, it should give a consistent behaviour on windows and linux. "this in mind" means: The only way how rtlevent should be used is: 1. c

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 20:33 schrieb Vinzent Höfler: > Burkhard Carstens wrote: > > Am Montag, 24. Juli 2006 19:22 schrieb Vinzent Höfler: > >> Burkhard Carstens wrote: > >>> Am Montag, 24. Juli 2006 17:27 schrieb Vinzent Hoefler: > > - the rtlEvent works even with timeout (with my patch post

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Micha Nelissen
Vinzent Höfler wrote: > Currently all I see is a subtle semantic difference between Windows- and > Unix-Event's implementation. AFAICS, it's as close as it can get. You mean subtle as in, unimportant, or as in, possibly fatal ? :-) If possibly fatal, describe when/how. > So for now all I can say

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 20:33 schrieb Vinzent Höfler: > Burkhard Carstens wrote: > > [..] > > > >> ... As long as rtlevent is used with this > >> in mind, it should give a consistent behaviour on windows and > >> linux. > > > > "this in mind" means: The only way how rtlevent should be used is: > >

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Florian Klaempfl wrote: I didn't understand and follow the whole thread but please submit a bug report if something in FPC needs to be fixed :) Well, I'll do as soon as I'm sure if there's a bug. :) Currently all I see is a subtle semantic difference between Windows- and Unix-Event's impleme

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Florian Klaempfl
Vinzent Höfler wrote: I didn't understand and follow the whole thread but please submit a bug report if something in FPC needs to be fixed :) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pas

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Burkhard Carstens wrote: [..] ... As long as rtlevent is used with this in mind, it should give a consistent behaviour on windows and linux. "this in mind" means: The only way how rtlevent should be used is: 1. call rtlstartwait 2. start the code (e.g. start/resume a thread), that signals the

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Burkhard Carstens wrote: Am Montag, 24. Juli 2006 19:22 schrieb Vinzent Höfler: Burkhard Carstens wrote: Am Montag, 24. Juli 2006 17:27 schrieb Vinzent Hoefler: - the rtlEvent works even with timeout (with my patch posted on mantis), but this one clears the signaled state, when wait is called.

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
[..] > ... As long as rtlevent is used with this > in mind, it should give a consistent behaviour on windows and linux. "this in mind" means: The only way how rtlevent should be used is: 1. call rtlstartwait 2. start the code (e.g. start/resume a thread), that signals the event. 3. call rtlwaiteve

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 19:22 schrieb Vinzent Höfler: > Burkhard Carstens wrote: > > Am Montag, 24. Juli 2006 17:27 schrieb Vinzent Hoefler: > >>> - the rtlEvent works even with timeout (with my patch posted on > >>> mantis), but this one clears the signaled state, when wait is > >>> called. > >>

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Höfler
Burkhard Carstens wrote: Am Montag, 24. Juli 2006 17:27 schrieb Vinzent Hoefler: - the rtlEvent works even with timeout (with my patch posted on mantis), but this one clears the signaled state, when wait is called. >> *oh* Before the wait? That's not good. This cries for race conditions and s

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 17:27 schrieb Vinzent Hoefler: > On Monday 24 July 2006 14:57, Burkhard Carstens wrote: > > I vote for more pascal based versions of TMutex, TSemaphore and > > TEvent, that behaves just like the ones in Delphi and use the > > system specific functions (like pthread stuff) o

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Hoefler
On Monday 24 July 2006 14:57, Burkhard Carstens wrote: > I vote for more pascal based versions of TMutex, TSemaphore and > TEvent, that behaves just like the ones in Delphi and use the system > specific functions (like pthread stuff) only internally in their > simplest/most portable form. I'd vot

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Burkhard Carstens
Am Montag, 24. Juli 2006 16:19 schrieb Vinzent Hoefler: > On Monday 24 July 2006 14:09, Michael Van Canneyt wrote: > > On Mon, 24 Jul 2006, Vinzent Hoefler wrote: > > > On Monday 24 July 2006 13:34, Marco van de Voort wrote: > > >>> When I run the Unit Tests and create a single Lock and the > > >>>

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Hoefler
On Monday 24 July 2006 14:09, Michael Van Canneyt wrote: > On Mon, 24 Jul 2006, Vinzent Hoefler wrote: > > On Monday 24 July 2006 13:34, Marco van de Voort wrote: > >>> 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 creat

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Michael Van Canneyt
On Mon, 24 Jul 2006, Vinzent Hoefler wrote: On Monday 24 July 2006 13:34, Marco van de Voort wrote: 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

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Vinzent Hoefler
On Monday 24 July 2006 13:34, Marco van de Voort wrote: > > 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

Re: [fpc-pascal] Semaphore problems

2006-07-24 Thread Marco van de Voort
> 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: Sounds like some recursion property is not set. >

[fpc-pascal] Semaphore problems

2006-07-24 Thread Graeme Geldenhuys
Hi, I am having troubles with porting Semaphores in a project under Linux. Under Windows everything works fine, but under Linux my app keeps freezing. The project is tiOPF v2 (TechInsite Object Persistent Framework). There is a class called TtiPool, that handles a pool of database connections.