multiple threads access to a large array

Discussion in 'C Programming' started by nicholas.entropy@gmail.com, May 19, 2009.

  1. Guest

    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
    , May 19, 2009
    #1
    1. Advertising

  2. On 19 May 2009 at 22:35, 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,&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.)
    Antoninus Twink, May 19, 2009
    #2
    1. Advertising

  3. 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,&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) <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"
    Keith Thompson, May 20, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K Gibbs
    Replies:
    1
    Views:
    345
    MiniDisc_2k2
    Jul 3, 2003
  2. Smegly
    Replies:
    1
    Views:
    1,096
    Mitchell
    May 19, 2004
  3. Ketchup
    Replies:
    1
    Views:
    243
    Jan Tielens
    May 25, 2004
  4. Martin DeMello

    efficient access to a large int32 array

    Martin DeMello, Jan 16, 2007, in forum: Ruby
    Replies:
    6
    Views:
    153
    Tim Pease
    Jan 16, 2007
  5. Bob Bobrov
    Replies:
    3
    Views:
    289
    Bob Bobrov
    Jun 19, 2008
Loading...

Share This Page