thread-safety

Interprocess SQLite Thread Safety (on iOS)

做~自己de王妃 提交于 2019-12-19 05:50:47
问题 I'm trying to determine if my sqlite access to a database is thread-safe on iOS. I'm writing a non App Store app (or possibly a launch daemon), so Apple's approval isn't an issue. The database in question is the built-in sms.db, so for sure the OS is also accessing this database for reading and writing. I only want to be able to safely read it. I've read this about reading from multiple processes with sqlite: Multiple processes can have the same database open at the same time. Multiple

Is std::regex thread safe?

谁说胖子不能爱 提交于 2019-12-19 05:46:05
问题 Related to Is a static boost::wregex instance thread-safe? but for the standarized version. Can I call regex_search from several threads with the same regex object? 回答1: Claiming that std::regex is thread-safe in every respect is a pretty bold statement. The C++11 standard does not make such guarantees for the regex library. However, looking at the prototype of std::regex_search shows that it it takes the basic_regex object as a const argument. This means that it is protected by the standard

Java ArrayList.add() method thread safe for purely parallel adding? [duplicate]

我的未来我决定 提交于 2019-12-19 04:24:15
问题 This question already has answers here : Collections.synchronizedList and synchronized (6 answers) Closed 5 years ago . Consider a for-loop over a function that takes an ArrayList reference and adds an object to that ArrayList. I would now like to execute each function call in parallel. Is the ArrayList.add() method thread safe if I don't care about the sequence the objects are added and no function reads or manipulates any ArrayList elements? So I only want to make sure that at the end of

Modifying hash map from a single thread and reading from multiple threads?

删除回忆录丶 提交于 2019-12-19 03:58:40
问题 I have a class in which I am populating a map liveSocketsByDatacenter from a single background thread every 30 seconds and then I have a method getNextSocket which will be called by multiple reader threads to get a live socket available which uses the same map to get this info. public class SocketManager { private static final Random random = new Random(); private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final Map<Datacenters, List

Modifying hash map from a single thread and reading from multiple threads?

风格不统一 提交于 2019-12-19 03:57:54
问题 I have a class in which I am populating a map liveSocketsByDatacenter from a single background thread every 30 seconds and then I have a method getNextSocket which will be called by multiple reader threads to get a live socket available which uses the same map to get this info. public class SocketManager { private static final Random random = new Random(); private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); private final Map<Datacenters, List

Thread-safety of read-only memory access

江枫思渺然 提交于 2019-12-19 03:39:06
问题 I've implemented the Barnes-Hut gravity algorithm in C as follows: Build a tree of clustered stars. For each star, traverse the tree and apply the gravitational forces from each applicable node. Update the star velocities and positions. Stage 2 is the most expensive stage, and so is implemented in parallel by dividing the set of stars. E.g. with 1000 stars and 2 threads, I have one thread processing the first 500 stars and the second thread processing the second 500. In practice this works:

GCC's TSAN reports a data race with a thread safe static local

我们两清 提交于 2019-12-19 02:43:06
问题 I wrote the following toy example: std::map<char, size_t> getMap(const std::string& s) { std::map<char, size_t> map; size_t i = 0; for (const char * b = s.data(), *end = b + s.size(); b != end; ++b) { map[*b] = i++; } return map; } void check(const std::string& s) { //The creation of the map should be thread safe according to the C++11 rules. static const auto map = getMap("12abcd12ef"); //Now we can read the map concurrently. size_t n = 0; for (const char* b = s.data(), *end = b + s.size();

Make an existing code in Java parallel/multithread

二次信任 提交于 2019-12-19 00:43:03
问题 I have a very simple crawler. I want to make my current code run in a few threads. Could you provide me a little tutorial or article to help me achive this test? I'm originally a .Net developer and in .Net I have no problem whatsoever running codes in multithread but unfortunately I don't know anything about threads in Java. My crawler is a command-line software so don't worry about GUI. Thank you in advance. 回答1: Java does multithreading through the Thread class. One of the most common ways

Is Django middleware thread safe?

给你一囗甜甜゛ 提交于 2019-12-18 19:02:28
问题 Are Django middleware thread safe? Can I do something like this, class ThreadsafeTestMiddleware(object): def process_request(self, request): self.thread_safe_variable = some_dynamic_value_from_request def process_response(self, request, response): # will self.thread_safe_variable always equal to some_dynamic_value_from_request? 回答1: Why not bind your variable to the request object, like so: class ThreadsafeTestMiddleware(object): def process_request(self, request): request.thread_safe

Java Concurrency Incrementing a Value

牧云@^-^@ 提交于 2019-12-18 17:08:24
问题 I have been reading about volatile and synchronized in Java but have been scratching my head in confusion. I am hoping someone can help me clear up a problem private HashMap<String,int> map = new HashMap<String,int>(); In my thread if (map.get("value") == null) { map.put("value",0); } map.put("value",map.get("value")+1); My goal is to have all the threads share this map . If I add volatile it doesn't seem to fix the problem for me (I output and see that map is being override to each time). I