Helmut Hartl pisze:
-----Original message-----
From: Dariusz Mazur <dar...@emadar.com>
Sent: Fri 18-09-2009 16:24
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>;
Subject: Re: [fpc-pascal] getting started with threads
David Emerson pisze:
I am getting started with threads (linux/cthreads) and I'm very happy so
far, but unsure of the best way to tackle my situation.
I have a program that needs to perform about 10,000 independent tasks,
which usually involve waiting for I/O; thus it makes sense to use
several threads so that some waiting can be done in parallel. I thought
I'd try it with 10 threads.
You need FIFO queue for multiple consumer. Each task can be assigned to
them.
You can use ordinal tThreadList but it rather slow.
I use own lockfree FIFO http://www.emadar.com/fpc/lockfree.htm to
distribute task between threads
its much faster and well scaling on multicore.
I had (only) a quick look at your implementation but i have the
bad feeling that it suffers from the ABA problem. Normally it has a
low probability to occur but nevertheless extremely hard to find errors
occur occasionally.
Its save about ABA problem, only it atomic operation are true atomic. I
try to test both: theoretical and in real. But if You know sequence,
that things may go wrong, pleas tell it.
The problem is avoided by using a 64 Bit CAS with a tagged pointer.
I have such a implementation under BSD Licence which i can donate for
review and public use. But it only works for 32 Bit x86 archs by now,
as i am not sure if there is a consistent support of a 128 Bit CAS on
all x86 chips. (my last knowledge was that not all xeon/pentium steppings support it)
64bit CAS is absent on many platforms, and is slower
but I'd like too see Your implementation
Have a look at (as example):
http://www.cs.rochester.edu/~scott/papers/1996_PODC_queues.pdf
Lot's of interesting publications in the field can be found at the ACM
(http://www.acm.org/),
but you need to be member to have access to the digital library.
thx for links
--
Darek
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal