multiple threads access to a large array

N

nicholas.entropy

hello, there are multiple threads get access to the different segments
of a large array, lets say, the first thread does quick sort to the
array[0]...array[10000], the second thread does the same to array
[10001]...array[20000], and so on. If the array is at global scope,
and because each thread is using different segments of the array,
when I call pthread_create(&threads,&attr,quicksort_begin,(void *)
i), do I have to use metux to lock the whole array for each thread? I
think it not necessary because each thread has its own segment. what
do you think?

Thank you very much for help.
nick
 
A

Antoninus Twink

If the array is at global scope, and because each thread is using
different segments of the array, when I call
pthread_create(&threads,&attr,quicksort_begin,(void *) i), do I
have to use metux to lock the whole array for each thread? I think it
not necessary because each thread has its own segment.


As long as two threads can never be trying to modify the same memory
location at once, there's no need for a mutex. It sounds like you're in
that situation. (Just because memory location X and memory location Y
are in the same array, there's no need to do any locking - it's the
writes into *X and *Y that would need protecting if X could be equal to
Y, not two writes into different locations that just happen to lie in
the same array.)
 
K

Keith Thompson

hello, there are multiple threads get access to the different segments
of a large array, lets say, the first thread does quick sort to the
array[0]...array[10000], the second thread does the same to array
[10001]...array[20000], and so on. If the array is at global scope,
and because each thread is using different segments of the array,
when I call pthread_create(&threads,&attr,quicksort_begin,(void *)
i), do I have to use metux to lock the whole array for each thread? I
think it not necessary because each thread has its own segment. what
do you think?


You should ask in comp.programming.threads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top