concurrency

make a variable last for a call stack

筅森魡賤 提交于 2020-01-03 20:02:04
问题 I have a class that contains some fields. I need to compare instances of this class by value, so I defined GetHashCode and Equals accordingly. Because the class allows circular references, I need a mechanism to avoid infinite recursion (for a more detailed explanation see Value-equals and circular references: how to resolve infinite recursion?). I solved this problem by modifying my Equals method so that it keeps track of the comparisons done before: class Foo { public string Name { get; set;

make a variable last for a call stack

霸气de小男生 提交于 2020-01-03 20:01:03
问题 I have a class that contains some fields. I need to compare instances of this class by value, so I defined GetHashCode and Equals accordingly. Because the class allows circular references, I need a mechanism to avoid infinite recursion (for a more detailed explanation see Value-equals and circular references: how to resolve infinite recursion?). I solved this problem by modifying my Equals method so that it keeps track of the comparisons done before: class Foo { public string Name { get; set;

When are MVar operations guaranteed to be uninterruptible?

倾然丶 夕夏残阳落幕 提交于 2020-01-03 18:55:08
问题 The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a mask ed block, saying: "The following operations are guaranteed not to be interruptible" takeMVar if the MVar is definitely full, and conversely putMVar if the MVar is definitely empty In what cases is an MVar "definitely" full or empty from the compiler's point of view? Is that even well-enough defined to enable reasoning about whether my code will break without handling async

When are MVar operations guaranteed to be uninterruptible?

孤街醉人 提交于 2020-01-03 18:55:06
问题 The documentation for Control.Exception describes which operations can have async exceptions thrown, even within a mask ed block, saying: "The following operations are guaranteed not to be interruptible" takeMVar if the MVar is definitely full, and conversely putMVar if the MVar is definitely empty In what cases is an MVar "definitely" full or empty from the compiler's point of view? Is that even well-enough defined to enable reasoning about whether my code will break without handling async

Azure Service Bus - avoid processing messages from same device in parallel

偶尔善良 提交于 2020-01-03 18:54:13
问题 A number of devices are sending messages which end up in a single Azure Service Bus queue (or topic). We want to process multiple messages in parallel, but we want to avoid concurrent processing of two messages of the same device at any given time. The following pictures illustrates the goal. There are 3 processing threads (in reality there might be several dozens, distributed between several servers). Each box denotes processing time of a single message, and the color shows which device it

Futures and Promises in Erlang

懵懂的女人 提交于 2020-01-03 17:24:18
问题 Does Erlang has equivalents for Future and Promises? Or since future and promises are solving a problem that doesn't exist in Erlang systems (synchronisation orchestrating for example), and hence we don't need them in Erlang. If I want the semantics of futures and promises in Erlang, they could be emulated via Erlang processes/actors? 回答1: You could easily implement a future in Erlang like this: F = fun() -> fancy_function() end, % fancy code Pid = self(), Other = spawn(fun() -> X = F(), Pid

Non-blocking concurrent message receive

自作多情 提交于 2020-01-03 15:39:20
问题 Is there a standard function to receive messages concurrent, but non-blocking? It seems like all the functions available in std.concurrency are blocking and the closest I found to something that is non-blocking is receiveTimeout however it still waits until the timeout. I would like it to return immediately if there are no messages passed to the thread. Here is what I came up with using receiveTimeout . module main; import std.concurrency; import std.stdio : writefln, readln; import core.time

Sending messages to functions in Scala

拥有回忆 提交于 2020-01-03 13:40:08
问题 I'm working my way through Bruce Tate's Seven Languages in Seven Weeks and am having a hard time understanding his implementation of sizer.scala (Scala: Day 3). In particular, consider the following Singleton object object PageLoader { def getPageSize(url : String) = Source.fromURL(url).mkString.length } and the following method that, using actors, calculates the number of characters in each web page given by the urls array. def getPageSizeConcurrently() = { val caller = self for(url <- urls)

Difference between return value of non-blocking flock function and the $wouldblock argument?

泄露秘密 提交于 2020-01-03 08:55:08
问题 I'm trying to understand non blocking flock and the wouldblock argument $fp = fopen('/tmp/lock.txt', 'r+'); if(flock($fp, LOCK_EX | LOCK_NB, $wouldblock)) { echo 'Lock obtained'; } else{ echo 'Unable to obtain lock'; } fclose($fp); Documentation says about wouldblock: The optional third argument is set to 1 if the lock would block (EWOULDBLOCK errno condition). Reproducing in a test enviroment the concurrent condition, if another process has gained lock, the flock function will immeditatly

How do scanf(), std::cin behave on multithreaded environment?

孤街浪徒 提交于 2020-01-03 08:49:11
问题 I'd like to state my problem using an example. Assuming there is an array of N /*(N>>1)*/ threads which are set to run this function: void Process() { //Some thread safe processing which requires in-deterministic computation time unsigned char byte; std::cin >> byte; } Once all of them are started simultaneously, what does happen? How are concurrent std::cin accesses handled? What does the end-user who operates on console see/experience? Edit: There is one more thing I'd like to add. Is the