Sign in Join

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

Mailing lists / lazarus / 2009-05

Thread safe

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

SteveG

Would appreciate anybody clearing this up for me -

If I use a TTimer on a GUI form to call a function, is the function within the Main thread at all times (therefore gui threadsafe) ?

If the above function then calls a function within a library, is the call still within the main thread (still safe) ?

and as a completely non-related question, does fpc/laz have a cross platform 'shared memory' component/function at the moment ?

Thanks heaps - SteveG

Reply by email

Mattias Gaertner
to SteveG
Would appreciate anybody clearing this up for me - If I use a TTimer on a GUI form to call a function, is the function within the Main thread at all times (therefore gui threadsafe) ?

yes

If the above function then calls a function within a library, is the call still within the main thread (still safe) ?

Yes.
Unless the library starts another thread.

and as a completely non-related question, does fpc/laz have a cross platform 'shared memory' component/function at the moment ?

Shared between what? Processes, libraries, computers?

Mattias

Reply by email

SteveG
to Mattias Gaertner
Show quoted text 7 lines
> and as a completely non-related question, does fpc/laz have a cross > platform 'shared memory' component/function at the moment ? Shared between what? Processes, libraries, computers? Mattias

Sorry, that shows too much focus on a small world doesn't it :) I meant sharing memory between multiple lazarus applications

Reply by email

SteveG
to Mattias Gaertner: On Sat, 30 May 2009 12:55:14 +1000 yes Yes. Unless the library starts another thread.…
Mattias Gaertner wrote 15 lines
On Sat, 30 May 2009 12:55:14 +1000 SteveG wrote: > Would appreciate anybody clearing this up for me - > > If I use a TTimer on a GUI form to call a function, is the function > within the Main thread at all times (therefore gui threadsafe) ? yes > If the above function then calls a function within a library, is the > call still within the main thread (still safe) ? Yes. Unless the library starts another thread.

One further assumption (to save a little time) -
If a TTimer is created within the 'Initialization' section of the Laz app, and the timer event calls a function within a library, all calls within that function, and any functions it calls should be thread/gui safe ?

Assuming the above to be true, can you tell me why the following 'sometimes' fails (works about 3 of 5 calls) when used from within the library function?

I pass the address of a WinCtrl (eg Label) to the function, then use the following

  TLabel( CompAddress^ ).Caption := 'test';

also a problem is 'Application.ProcessMessages' within the library

These (and variations of) seem to fail regularly, but work fine from the Laz app itself

Thanks

Reply by email

Mattias Gaertner
to SteveG
Show quoted text 23 lines
On Saturday 30 May 2009 17:09:41 Mattias Gaertner wrote: > On Sat, 30 May 2009 12:55:14 +1000 > > SteveG wrote: > > Would appreciate anybody clearing this up for me - > > > > If I use a TTimer on a GUI form to call a function, is the > > function within the Main thread at all times (therefore gui > > threadsafe) ? > > yes > > > If the above function then calls a function within a library, is > > the call still within the main thread (still safe) ? > > Yes. > Unless the library starts another thread. One further assumption (to save a little time) - If a TTimer is created within the 'Initialization' section of the Laz app, and the timer event calls a function within a library, all calls within that function, and any functions it calls should be thread/gui safe ?

The TTimer events are called by the main gui thread. I don't know if this fits your thread safety definition.

Show quoted text 12 lines
Assuming the above to be true, can you tell me why the following 'sometimes' fails (works about 3 of 5 calls) when used from within the library function? I pass the address of a WinCtrl (eg Label) to the function, then use the following TLabel( CompAddress^ ).Caption := 'test'; also a problem is 'Application.ProcessMessages' within the library These (and variations of) seem to fail regularly, but work fine from the Laz app itself

I can't say without knowing the code. Please provide an example.

Mattias

Reply by email

SteveG
to Mattias Gaertner
Show quoted text 12 lines
> > I pass the address of a WinCtrl (eg Label) to the function, then use > the following > TLabel( CompAddress^ ).Caption := 'test'; > > also a problem is 'Application.ProcessMessages' within the library > > These (and variations of) seem to fail regularly, but work fine from > the Laz app itself I can't say without knowing the code. Please provide an example.

Will do - just have to attempt to distill the relevant code - Thanks

Reply by email