[Lazarus] thread safe

Malcom Haak insanemal at gmail.com
Tue Jun 28 01:24:52 CEST 2011


However there are MANY cases where execution order does not matter. These
are the BEST cases for threads.
In most of these cases there is a long list of work to be done, none of
which references any of the other work. Some examples include brute force
solving of complex hashing functions,
downloading of large lists of files or basically any time you have lots of
'slow' work that you know all the details about in advance.
In these cases all you have are self-contained threads that need to pull
from one list and possibly push answers to another.

Tell me then why any of what you have said is relevant. In fact in cases
this this the use of CriticalSections would be sensible and would not cause
'tons of wait' as you have all your worker threads off doing things 99% of
the time.

Also If you have lots of code that requires things to happen in specific
orders, I think you need to re-evaluate your use of threads. Attempts to
make things that require synchronous processing or order, suddenly
asynchronous is just stupid and fraught with issues. Most of the time you
should find a 'string of tasks' that can be done asynchronously, this is
what you get threads to do. IF all the processing you have
requires specific execution order then don't use threads.. The other
possibility is that you are just doing it wrong.

I don't see how the idea of Execution order is that hard, it should be seen
like giving tasks to 100's of people when organising a large event or
something. I think most of the 'difficulty' for programmers with
multi-threading is understanding how to delegate.


On Tue, Jun 28, 2011 at 8:31 AM, Andrew Brunner
<andrew.t.brunner at gmail.com>wrote:

> On Mon, Jun 27, 2011 at 2:51 PM, Hans-Peter Diettrich
> <DrDiettrich1 at aol.com> wrote:
> >> Absolutely incorrect.
> >
> > Why?
> >
>
> Two reasons.
>
> 1.) Visibility.  A critical section does not particularly protect
> visibility as with 2 threads accessing a piece of memory.
>
> 2.) Execution Order.  A critical section does not protect or ensure
> that code will be executed in any particular order.  This is where
> multi-core/multi-threaded systems vs theory get extremely complicated.
>  AMD vs Intel.  Kernels Linux vs Windows.  The only way to make sure
> you can get code in proper order with regard to memory assignments (
> specifically variables) is to use Interlocked methods.  This is why
> they were designed.
>
> The analogy would be like using a wisk vs a commerical grade mixer to
> scramble your eggs.  Use the commercial grade mixer in this case
> (CriticalSection) and expect a high cost of use and tons of wait
> states - which translates into poor benchmarks.
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110628/3f960000/attachment-0003.html>


More information about the Lazarus mailing list