Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > multiple threads access to a large array

Reply
Thread Tools

multiple threads access to a large array

 
 
nicholas.entropy@gmail.com
Guest
Posts: n/a
 
      05-19-2009
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[i],&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
 
Reply With Quote
 
 
 
 
Antoninus Twink
Guest
Posts: n/a
 
      05-19-2009
On 19 May 2009 at 22:35, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> If the array is at global scope, and because each thread is using
> different segments of the array, when I call
> pthread_create(&threads[i],&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.)

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      05-20-2009
(E-Mail Removed) writes:
> 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[i],&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.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads and synchronized access to an array Bob Bobrov Ruby 3 06-19-2008 10:54 AM
efficient access to a large int32 array Martin DeMello Ruby 6 01-16-2007 07:51 PM
[Urgent] Is there a size limit on returning a large dataset or a large typed array from web service? Ketchup ASP .Net Web Services 1 05-25-2004 10:11 AM
running multiple threads and multiple processes at the same time Smegly C Programming 1 05-19-2004 02:59 AM
how to limit access to common objects shared among multiple threads K Gibbs C++ 1 07-03-2003 10:32 PM



Advertisments