thread-safety

Blocking Queue Take out of Order

烂漫一生 提交于 2021-01-24 18:24:52
问题 I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new LinkedBlockingQueue<Integer>(); The goal is to have adding in order.. and taking be in the same order as well. On the 5th line of my program output, 3 is somehow at the front of the queue before 2 is, despite it appearing that 2 was added first. All of these were added in a single threaded environment, so I know the

Thread Safety of LibAv/FFMpeg?

六眼飞鱼酱① 提交于 2021-01-21 04:49:41
问题 Is LibAV/FFMpeg thread safe? For example. Could i read from a file using AVFormatContext* in one thread and decode the read packet it in another with simple additions of mutexes or is the thread safetyness of the library a "don't know don't care" type deal? I know that libav has basic support for encoder threads but i'm trying more of a blackbox type approach where i break it up into multiple threads (Source -> Decoder -> Filter -> Encoder -> Sink) and trying to understand the complications

Thread Safety of LibAv/FFMpeg?

北城余情 提交于 2021-01-21 04:49:26
问题 Is LibAV/FFMpeg thread safe? For example. Could i read from a file using AVFormatContext* in one thread and decode the read packet it in another with simple additions of mutexes or is the thread safetyness of the library a "don't know don't care" type deal? I know that libav has basic support for encoder threads but i'm trying more of a blackbox type approach where i break it up into multiple threads (Source -> Decoder -> Filter -> Encoder -> Sink) and trying to understand the complications

Is it possible to create a pause in the middle of Swing application?

为君一笑 提交于 2021-01-20 12:50:18
问题 I'm working on a project that involves access by reading a String from a physical card, the following code simplifies the main point of my program, however when I try to make a pause for a few seconds after an user has swipe his card, something goes wrong and the behavior is not what I need, the program pauses but the color's pane doesn't change nor the label. Any suggestion? This is the code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class B2 extends JFrame

Java ConcurrentHashMap and for each loop

风格不统一 提交于 2021-01-20 08:09:47
问题 Supposed I have the following ConcurrentHashMap : ConcurrentHashMap<Integer,String> identificationDocuments = new ConcurrentHashMap<Integer,String>(); identificationDocuments.put(1, "Passport"); identificationDocuments.put(2, "Driver's Licence"); How would I safely iterate over the map with a for each loop and append the value of each entry to a string? 回答1: Iterators produced by a ConcurrentHashMap are weakly consistent. That is: they may proceed concurrently with other operations they will

Java ConcurrentHashMap and for each loop

女生的网名这么多〃 提交于 2021-01-20 08:07:28
问题 Supposed I have the following ConcurrentHashMap : ConcurrentHashMap<Integer,String> identificationDocuments = new ConcurrentHashMap<Integer,String>(); identificationDocuments.put(1, "Passport"); identificationDocuments.put(2, "Driver's Licence"); How would I safely iterate over the map with a for each loop and append the value of each entry to a string? 回答1: Iterators produced by a ConcurrentHashMap are weakly consistent. That is: they may proceed concurrently with other operations they will

Run code in main thread

与世无争的帅哥 提交于 2021-01-02 06:23:07
问题 It's similar to many questions, but not rly. I need something like BeginInvoke for Winforms, but not for winforms only. So i need single method, that works for any type of application, so i'm calling void ExecuteInMainContext(Action action) { ... } and it should work, be called from Console, winforms, wpf and so on. All methods i saw was using BeginInvoke for winforms, Dispatcher.Invoke for WPF etc. But i should call it from library and i don't know from where it's called. And it also should

How to create a synchronized object with Python multiprocessing?

假如想象 提交于 2020-12-29 07:57:48
问题 I am trouble figuring out how to make a synchronized Python object. I have a class called Observation and a class called Variable that basically looks like (code is simplified to show the essence): class Observation: def __init__(self, date, time_unit, id, meta): self.date = date self.time_unit = time_unit self.id = id self.count = 0 self.data = 0 def add(self, value): if isinstance(value, list): if self.count == 0: self.data = [] self.data.append(value) else: self.data += value self.count +=

How to create a synchronized object with Python multiprocessing?

喜夏-厌秋 提交于 2020-12-29 07:57:26
问题 I am trouble figuring out how to make a synchronized Python object. I have a class called Observation and a class called Variable that basically looks like (code is simplified to show the essence): class Observation: def __init__(self, date, time_unit, id, meta): self.date = date self.time_unit = time_unit self.id = id self.count = 0 self.data = 0 def add(self, value): if isinstance(value, list): if self.count == 0: self.data = [] self.data.append(value) else: self.data += value self.count +=

How to disable thread safety in PHP?

此生再无相见时 提交于 2020-12-08 07:05:55
问题 I am using some software that requires me to have thread safety disabled. I am working on a Windows server. From what I've read elsewhere, I can't just configure this in the .ini file. Is this true? If so, how would I compile it so that thread safety is turned off? 回答1: You have to compile PHP with ZTS disabled (compile flag --disable-zts ) or download binaries with ZTS disabled. This won't work properly in some webservers, namely those which process several PHP scripts simultaneously in the