Scott
Scott

Reputation: 21

Function Accessed by Multiple Threads with Parameter Passed by Reference

I am in vb.net and have a function that will be accessed by multiple threads. Everything inside the function uses local variables. However, each thread will pass in its own dataset by reference.

From what I have read the local variables should be no problem, but I think the dataset coming in is a concern.

How should I control access / execution of this function to make sure that it is thread safe? Thanks.

Upvotes: 2

Views: 707

Answers (1)

Michael Burr
Michael Burr

Reputation: 340268

Assuming that by 'dataset' you mean a System.Data.DataSet, if your function is only reading from the dataset, then you don't need synchronization in any case since "This type is safe for multithreaded read operations" (from http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx).

If you're modifying the dataset, then as long as each dataset is a different instance, there should be no problem.

If you're modifying the data and if different threads might pass in a reference to the same dataset, you'll need to synchronize access to the dataset using a Monitor (SyncLock or lock in C#) or some other synchronization technique.

Upvotes: 2

Related Questions