开发者

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 acces开发者_如何学运维s / execution of this function to make sure that it is thread safe? Thanks.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜