Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-08

notify and notigyall

16 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marco van de Voort
to ik
Is there an equivalent for Java's sleep and notify/notifyAll in FPC's rtl ?

I'm sorry. I don't know Java that well. Maybe it is easier to describe the exact behaviour that you want instead of drawing a parallel

Reply by email

ik
to Marco van de Voort
Marco van de Voort wrote
> Is there an equivalent for Java's sleep and notify/notifyAll in FPC's rtl ? I'm sorry. I don't know Java that well. Maybe it is easier to describe the exact behaviour that you want instead of drawing a parallel

Lets say I have synchronized threads, because I do not want to arrive to a race condition.
So I want one thread to sleep as long as another thread is running... now "sleep" or "wait" I don't remember, sleep to infinitum unless I'm notifying the thread.
Now if I have more then one thread (for example) that is looking for something to finish, I should need to tell every such thread to continue running, so I'll use notifyAll.

Ido

Reply by email

Mattias Gaertner
to ik
Show quoted text 16 lines
On 8/23/07, Marco van de Voort wrote: > > Is there an equivalent for Java's sleep and notify/notifyAll in > > FPC's rtl ? > > I'm sorry. I don't know Java that well. Maybe it is easier to > describe the exact behaviour that you want instead of drawing a > parallel Lets say I have synchronized threads, because I do not want to arrive to a race condition. So I want one thread to sleep as long as another thread is running... now "sleep" or "wait" I don't remember, sleep to infinitum unless I'm notifying the thread. Now if I have more then one thread (for example) that is looking for something to finish, I should need to tell every such thread to continue running, so I'll use notifyAll.

Maybe you can try

http://www.freepascal.org/docs-html/rtl/system/rtleventwaitfor.html

If this works, you can write a small example for the wiki: http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

Mattias

Reply by email

ik
to Mattias Gaertner
Mattias Gaertner wrote 26 lines
On Thu, 23 Aug 2007 21:32:41 +0300 ik wrote: > On 8/23/07, Marco van de Voort wrote: > > > Is there an equivalent for Java's sleep and notify/notifyAll in > > > FPC's rtl ? > > > > I'm sorry. I don't know Java that well. Maybe it is easier to > > describe the exact behaviour that you want instead of drawing a > > parallel > > Lets say I have synchronized threads, because I do not want to arrive > to a race condition. > So I want one thread to sleep as long as another thread is running... > now "sleep" or "wait" I don't remember, sleep to infinitum unless I'm > notifying the thread. > Now if I have more then one thread (for example) that is looking for > something to finish, I should need to tell every such thread to > continue running, so I'll use notifyAll. Maybe you can try http://www.freepascal.org/docs-html/rtl/system/rtleventwaitfor.html If this works, you can write a small example for the wiki: http://wiki.lazarus.freepascal.org/Multithreaded_Application_Tutorial

Thanks, that's what I was looking for.

Mattias

Ido

Reply by email

Luca Olivetti
to Mattias Gaertner: On Thu, 23 Aug 2007 21:32:41 +0300 Maybe you can try…

En/na Mattias Gaertner ha escrit:

Show quoted text 7 lines

How are these different to the TEventObject,TSimpleEvent classes in syncobjs? Just curious, since I usually do with syncobjs, and I don't see a big difference between MyEvent.SetEvent/MyEvent.WaitFor and RTLEventSetEvent/RTLEventWaitFor

Bye

Luca

Reply by email

Jonas Maebe
to Luca Olivetti
Luca Olivetti wrote
How are these different to the TEventObject,TSimpleEvent classes in syncobjs? Just curious, since I usually do with syncobjs, and I don't see a big difference between MyEvent.SetEvent/MyEvent.WaitFor and RTLEventSetEvent/RTLEventWaitFor

If you look at the source of syncobjs, you'll notice teventobject is just an OO coat for tbasicrtlevent.

Jonas

Reply by email

Vinzent Hoefler
to Jonas Maebe: If you look at the source of syncobjs, you'll notice teventobject is just an OO coat for…
Jonas Maebe wrote 8 lines
On 23 Aug 2007, at 21:29, Luca Olivetti wrote: > How are these different to the TEventObject,TSimpleEvent classes in > syncobjs? Just curious, since I usually do with syncobjs, and I > don't see a big difference between MyEvent.SetEvent/MyEvent.WaitFor > and RTLEventSetEvent/RTLEventWaitFor If you look at the source of syncobjs, you'll notice teventobject is just an OO coat for tbasicrtlevent.

Last time I looked this is only true for Win32, the Unix version seems to be very different and is implemented with semaphores. Is there a reason why those routines are not simply based POSIX condition variables?

Vinzent.

Reply by email

Michael Van Canneyt
to Vinzent Hoefler
Vinzent Hoefler wrote 14 lines
On Thursday 23 August 2007 19:47, Jonas Maebe wrote: > On 23 Aug 2007, at 21:29, Luca Olivetti wrote: > > How are these different to the TEventObject,TSimpleEvent classes in > > syncobjs? Just curious, since I usually do with syncobjs, and I > > don't see a big difference between MyEvent.SetEvent/MyEvent.WaitFor > > and RTLEventSetEvent/RTLEventWaitFor > > If you look at the source of syncobjs, you'll notice teventobject is > just an OO coat for tbasicrtlevent. Last time I looked this is only true for Win32, the Unix version seems to be very different and is implemented with semaphores. Is there a reason why those routines are not simply based POSIX condition variables?

Yes: a single source base. All 'basic' threading routines are in the system unit, all the rest is based on that.

Michael.

Reply by email

Vinzent Hoefler
to Michael Van Canneyt
Michael Van Canneyt wrote 19 lines
On Fri, 24 Aug 2007, Vinzent Hoefler wrote: > On Thursday 23 August 2007 19:47, Jonas Maebe wrote: > > On 23 Aug 2007, at 21:29, Luca Olivetti wrote: > > > How are these different to the TEventObject,TSimpleEvent > > > classes in syncobjs? Just curious, since I usually do with > > > syncobjs, and I don't see a big difference between > > > MyEvent.SetEvent/MyEvent.WaitFor and > > > RTLEventSetEvent/RTLEventWaitFor > > > > If you look at the source of syncobjs, you'll notice teventobject > > is just an OO coat for tbasicrtlevent. > > Last time I looked this is only true for Win32, the Unix version > seems to be very different and is implemented with semaphores. Is > there a reason why those routines are not simply based POSIX > condition variables? Yes: a single source base. All 'basic' threading routines are in the system unit, all the rest is based on that.

Yes, I figured that this was the idea. I don't have access to the current SVN version (not before this evening when I am back home) to adequately show what I mean, but - from my bad memory - the question remains why

1) the Unix version makes so strange and wild efforts to support WaitFor with timeouts if there is pthread_cond_timed_wait() (and this is used elsewhere already) and
2) why the SyncObjs tEvent objects uses those semaphore stuff instead of the fixed RTLEvents.

Vinzent.

Reply by email

Michael Van Canneyt
to Vinzent Hoefler
Vinzent Hoefler wrote 29 lines
On Friday 24 August 2007 07:55, Michael Van Canneyt wrote: > On Fri, 24 Aug 2007, Vinzent Hoefler wrote: > > On Thursday 23 August 2007 19:47, Jonas Maebe wrote: > > > On 23 Aug 2007, at 21:29, Luca Olivetti wrote: > > > > How are these different to the TEventObject,TSimpleEvent > > > > classes in syncobjs? Just curious, since I usually do with > > > > syncobjs, and I don't see a big difference between > > > > MyEvent.SetEvent/MyEvent.WaitFor and > > > > RTLEventSetEvent/RTLEventWaitFor > > > > > > If you look at the source of syncobjs, you'll notice teventobject > > > is just an OO coat for tbasicrtlevent. > > > > Last time I looked this is only true for Win32, the Unix version > > seems to be very different and is implemented with semaphores. Is > > there a reason why those routines are not simply based POSIX > > condition variables? > > Yes: a single source base. All 'basic' threading routines are in the > system unit, all the rest is based on that. Yes, I figured that this was the idea. I don't have access to the current SVN version (not before this evening when I am back home) to adequately show what I mean, but - from my bad memory - the question remains why 1) the Unix version makes so strange and wild efforts to support WaitFor with timeouts if there is pthread_cond_timed_wait() (and this is used elsewhere already) and

This I don't know; I didn't implement it.

2) why the SyncObjs tEvent objects uses those semaphore stuff instead of the fixed RTLEvents.

It's based on the Windows implementation, as far as I know ?

Michael.

Reply by email

Jonas Maebe
to Vinzent Hoefler: Last time I looked this is only true for Win32, the Unix version seems to be very…
Vinzent Hoefler wrote 5 lines
> If you look at the source of syncobjs, you'll notice teventobject is > just an OO coat for tbasicrtlevent. Last time I looked this is only true for Win32, the Unix version seems to be very different and is implemented with semaphores.

Someone submitted a patch a while ago to make this so for all platforms. The reason it was different for Unix was that this unit predates the existence of tbasicrtlevent.

Is there a reason why those routines are not simply based POSIX condition variables?

tbasicrtlevent for Unix is still not based on condition variables, because Windows events are persistent and condition variables are not.

Jonas

Reply by email

Vinzent Hoefler
to Jonas Maebe: Someone submitted a patch a while ago to make this so for all platforms. The reason it…
Jonas Maebe wrote
tbasicrtlevent for Unix is still not based on condition variables, because Windows events are persistent and condition variables are not.

Call me stupid, but I was under the impression that this has been fixed by inserting the "IsSet" member in the IntRTLEvent structure (this fix also made RTLEventStartWait disappear for exactly that reason).

Vinzent.

Reply by email

Jonas Maebe
to Vinzent Hoefler
Vinzent Hoefler wrote 7 lines
On Friday 24 August 2007 08:53, Jonas Maebe wrote: > tbasicrtlevent for Unix is still not based on condition variables, > because Windows events are persistent and condition variables are > not. Call me stupid,

If you insist :)

but I was under the impression that this has been fixed by inserting the "IsSet" member in the IntRTLEvent structure (this fix also made RTLEventStartWait disappear for exactly that reason).

There are two different event families: intrtlevent and basicrtlevent. I have no idea what the history behind the two different taxonomies is, nor what their supposed functional differences are. basicrtlevent was implemented from the start using semaphores, intrtlevent using conditional variables. syncobjs uses basicrtlevent.

It's indeed possible that by now due to all of the fixes everywhere, they both provide exactly the same functionality, but I would have to check (also the Windows implementation, to see whether there are any differences over there).

Jonas

Reply by email