Thread: New threading question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    222

    New threading question

    What actually happens when I make a thread and pass a vector reference to it which i fill in the thread. example : let say I have a function that takes a vector reference and adds numbers to it. and i thread that function into two threads. is the acces to the passed vector somehow coordinated or is there a possibility ffor two threads to write to the same location in that vector:

    Code:
    void Func(vector<int>& xx){
       for(...)
         xx.push_back(i);
    }
    
    
    void main(){
    
          threads ...
          vec ...
    
           for (int i = 0; i < 2; ++i) 
             threads.push_back(thread(Func, ref(vec)));
    
           for(auto &t : threads)
              t.join();
    }
    will two threads sinc their access and push back or is it up to me to do that ??

    thnx


    PS the above is a form of pseudo-code
    Last edited by baxy; 07-03-2015 at 03:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Amateur Threading Question
    By ThePermster in forum C# Programming
    Replies: 1
    Last Post: 07-31-2009, 06:27 PM
  2. Threading Question
    By CornyKorn21 in forum C++ Programming
    Replies: 3
    Last Post: 05-30-2008, 11:13 AM
  3. c++ threading
    By Anddos in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2005, 03:29 PM
  4. Threading
    By nc3b in forum C++ Programming
    Replies: 7
    Last Post: 11-18-2005, 02:06 AM
  5. Help with threading
    By crazeinc in forum C Programming
    Replies: 2
    Last Post: 06-02-2005, 05:23 PM