NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pthreads condition variables
On Tue, Nov 17, 2009 at 07:53:09PM +0000, raymond.meyer%rambler.ru@localhost
wrote:
> I want to use all 256 threads to perform some computation in parallel.
>
> 1. create 256 threads
> 2. threads go to sleep waiting for work
> 3. partition data into 256 parallel regions
> 4. signal all threads to process data
>
> When threads go to sleep on line 2, they execute:
>
> pthread_cond_wait(&cond, &mutex)
>
> When the main thread signals all threads on line 4, it executes:
>
> pthread_cond_broadcast(&cond)
Why don't you use pthread_cond_signal() and let one worker thread
pick up one work item.
> Because the data is partitioned into 256 parallel regions, each thread
> works on a different data set, hence no need for mutual exclusion.
You don't necessarily have to have a fixed assignment between thread
and data partitions. You only have to make sure that at any time
only one thread access a partition.
Kind regards
--
Matthias Scheler http://zhadum.org.uk/
Home |
Main Index |
Thread Index |
Old Index