I have the following class.
class Test{
public HashSet Data = new HashSet();
}
I need to change the field "Data" from different threads, so I would like some opinions on my current thread-safe implementation.
class Test{
public HashSet Data = new HashSet();
public void Add(string Val){
lock(Data) Data.Add(Val);
}
public void Remove(string Val){
lock(Data) Data.Remove(Val);
}
}
Is there a better solution, to go directly to field and protect it from concurrent access by multiple threads?
Your Answer
0 answers
Hot tools Tags
Hot Questions
Calculating Distance between two Latitude and Longitude GeoCoordinates
2025-12-31 22:43:11
Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?
2025-12-31 22:22:10
Truncate Two decimal places without rounding
2025-12-31 22:01:15
How to generate and validate a software license key?
2025-12-31 21:43:15
PhpMailer vs. SwiftMailer? [closed]
2025-12-31 21:22:11
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
Douyin level price list 1-75
20416
7
20416
7
wifi shows no ip assigned
13574
4
13574
4






