Pass reference of object to a new Thread

后端 未结 4 379
天命终不由人
天命终不由人 2020-12-20 01:29

I have an object that contains a very large 3D-array of doubles and I need to start a new thread that need the data of this array, so I will either need to start a new threa

4条回答
  •  旧时难觅i
    2020-12-20 01:41

    By reference.

    If you change the data in your thread it will change the original data you put in. Same applies if you change the data outside the thread your thread will see the modified data.

    You need proper locking mechanisms so that it will not collide when accessing the data from multiple threads.

提交回复
热议问题