thread-safety

Problems with race conditions on ConcurrentHashMap

◇◆丶佛笑我妖孽 提交于 2021-02-10 23:54:04
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

Problems with race conditions on ConcurrentHashMap

ⅰ亾dé卋堺 提交于 2021-02-10 23:48:27
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

Problems with race conditions on ConcurrentHashMap

自古美人都是妖i 提交于 2021-02-10 23:47:45
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

“Any public static members of XmlDocument are thread safe. Any instance members are not guaranteed to be thread safe” : yes, but

廉价感情. 提交于 2021-02-10 14:19:42
问题 I see in the XmlDocument class documentation on MSDN that Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. Same thing for the XmlNodeList class. I am using those classes in the following context. Inside a Parallel.Foreach I do : X MyX = new X(); string XMLstring = MyX.GetXML(ID, true); XmlDocument doc = new XmlDocument(); doc.LoadXml(XMLstring); XmlNodeList nodeList = doc.SelectNodes("blah/secondblah")

Update item in ObservableCollection as Thread safe

点点圈 提交于 2021-02-08 12:15:29
问题 Is there any good way to update a Item in ObservableCollection as "Thread safe" ? Here is my way. var target = MyCollection.Where(i => i.Key== a_Key).Single(); MyCollection[MyCollection.IndexOf(target)] = NewValue; But I worry. If I use Index, It may not thread safe.. Please advice me. In internet, THere is some thread-safe-ObservableCollection. I want to use No.1. Is there any better way ? https://gist.github.com/thomaslevesque/10023516 https://www.codeproject.com/Articles/64936

“Starting new Thread in constructor” warning in Lambda expression (NetBeans IDE)

爷,独闯天下 提交于 2021-02-08 07:34:20
问题 When I start new thread in traditional constructor, NetBeansIDE gives no warnings: addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { (new SomeThread()).start(); } }); But if I convert it to Lambda expression, I'm getting a warning "Starting new Thread in constructor": addActionListener((ActionEvent e) -> { (new SomeThread()).start(); }); What is the problem here? What is the correct solution? EDIT 1: The same problem on NetBeans IDE 8.0.2: The

Two waiting threads (producer/consumer) with a shared buffer

余生长醉 提交于 2021-02-07 20:28:44
问题 I am trying to have a bunch of producer threads that wait untill the buffer has room for an item, then it puts items in the buffer while it can, going back to sleep if there is no more room. At the same time there should be a bunch of consumer threads that wait untill there is something in the buffer, then it takes things from buffer while it can, going back to sleep if it's empty. In pseudo code, here's what Iam doing, but all Iam getting is deadlocks. condition_variable cvAdd; condition

Does this envelope implementation correctly use C++11 atomics?

ぃ、小莉子 提交于 2021-02-07 13:15:54
问题 I have written a simple 'envelope' class to make sure I understand the C++11 atomic semantics correctly. I have a header and a payload, where the writer clears the header, fills in the payload, then fills the header with an increasing integer. The idea is that a reader then can read the header, memcpy out the payload, read the header again, and if the header is the same the reader can then assume they successfully copied the payload. It's OK that the reader may miss some updates, but it's not

Create a Windows Form from a background Thread

烈酒焚心 提交于 2021-02-07 09:32:36
问题 I'm developing a VS Package and I have this problem: I have a Background-Thread which checks every few seconds for specific changes that have to be done. This includes changing the GUI of VS 2010, which works perfectly fine without an invoke for some reason. Anyway if I try to open a new Form, it opens, but it doesn't show anything, kind of crashes and doesn't respond. I've already tried Application.OpenForms[0].invoke( /* delegate to create the form */) . This works fine, but I don't have an

Create a Windows Form from a background Thread

戏子无情 提交于 2021-02-07 09:31:44
问题 I'm developing a VS Package and I have this problem: I have a Background-Thread which checks every few seconds for specific changes that have to be done. This includes changing the GUI of VS 2010, which works perfectly fine without an invoke for some reason. Anyway if I try to open a new Form, it opens, but it doesn't show anything, kind of crashes and doesn't respond. I've already tried Application.OpenForms[0].invoke( /* delegate to create the form */) . This works fine, but I don't have an