concurrency

Could the side effect of atomic operation be seen immediately by other threads?

…衆ロ難τιáo~ 提交于 2019-12-24 22:29:20
问题 In this question one replier says Atomicity means that operation either executes fully and all it's side effects are visible , or it does not execute at all. However, below is an example given in Concurrency in Action $Lising 5.5 #include <thread> #include <atomic> #include <iostream> std::atomic<int> x(0),y(0),z(0); std::atomic<bool> go(false); unsigned const loop_count=10; struct read_values { int x,y,z; }; read_values values1[loop_count]; read_values values2[loop_count]; read_values

Start concurrent batches with filename mask and wait for them to finish

白昼怎懂夜的黑 提交于 2019-12-24 19:54:11
问题 I'm trying to start a fixed number of concurrent batch processes that have similar filenames, all in the same directory: TestMe1.bat TestMe2.bat TestMe3.bat All batches should start at the same time, and all should complete before the batch continues, e.g. a master.bat: echo Starting batches ( start "task1" cmd /C "TestMe1.bat" start "task2" cmd /C "TestMe2.bat" start "task3" cmd /C "TestMe3.bat" ) | pause echo All batches have stopped and we can safely continue I'm trying to find a way to

several concurrent URL calls

隐身守侯 提交于 2019-12-24 19:07:21
问题 How can I make, say N url calls in parallel, and process the responses as they come back? I want to ready the responses and print them to the screen, maybe after some manipulations. I don't care about the order of the responses. 回答1: You can use Twisted Python for this, such as in the example here: https://twistedmatrix.com/documents/13.0.0/web/howto/client.html#auto3 Twisted is an asynchronous programming library for Python which lets you carry out multiple actions "at the same time," and it

How to efficiently close the channel?

白昼怎懂夜的黑 提交于 2019-12-24 18:31:38
问题 I'm trying to do some stuff: type Feed struct { title, descr, link string published time.Time } func main() { ar := make([]Feed, 0) for i := 0; i < 3; i++ { f: = new(Feed) // do some stuff with feed ar = append(ar, *f) } ch := make(chan Feed, 3) for _, i := range ar { go process(i, ch) } r :=0 for i := range ch { fmt.Println(i) r++ if r == 3 { close(ch) } } } func process(i Feed, ch chan Feed) { // do some stuff ch <- i } It seems that ar is unnecessary, but if it would be removed, last range

PHP - why global variables are evil

给你一囗甜甜゛ 提交于 2019-12-24 18:17:15
问题 I know this has already been discussed multiple times here but I would like to further and clear understanding why it's bad practice to use global variables. Does it becomes dangerous on the concurrent http requests? if this is the code: <?php $variable1 = $_REQUEST['userinput']; sleep(3000); echo $variable1; ?> if there are users like user1, user2.. if user1's input is 'request1' and user2's input is 'request2' that is passed to $_REQUEST['userinput'] variable, then concurrent sending of

Handling unexpected exceptions on scala Futures

﹥>﹥吖頭↗ 提交于 2019-12-24 17:44:13
问题 When using some code like the following: scala> Future { null } onComplete { case Success(v) => v.toString } Scala throws the following exception: scala> java.lang.NullPointerException at $line14.$read$$iw$$iw$$anonfun$2.apply(<console>:11) at $line14.$read$$iw$$iw$$anonfun$2.apply(<console>:11) at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) at scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107) at scala.concurrent.forkjoin.ForkJoinTask

Using JFrame with a Continuous Input Stream

坚强是说给别人听的谎言 提交于 2019-12-24 17:16:35
问题 I'm trying to implement code which reads from my redboard's serial port and based on what it reads have it repaint a circle. The end goal of this is to use the Robot class to achieve actual cursor control, but I first want to learn more about Java along the way and so I'm trying to achieve it with some basic graphics first. To summarize my issue, I do not know how to use JFrame with a continuously changing input from a static method. The serial port accessing JAR can be found at http:/

Duplicate key exception on merge statement in DB2

流过昼夜 提交于 2019-12-24 17:06:35
问题 The problem: Everyday we get lots of parts that we want to add to our stock. We get messages over a queue that we read from (using 4 different servers). The queue always contains elements so the servers read as fast as they can. We want the servers to simply update the article if the article exits, and insert it if it doesn't. Our first, naive solution was simply to select to see if the article existed, and if it didn't we wanted to insert. However since there was no row for us to lock we got

Most efficient matrix multiplication in C using fork() and IPC

半城伤御伤魂 提交于 2019-12-24 16:46:35
问题 I need to implement concurrent matrix multiplication in C using multiple processes. I understand that because each process has its own private address space, I will have to use some form of interprocess communication (IPC). I did some looking around and couldn't find many implementations that didn't use threads. I was wondering if anyone knew the most best way to go about this, either using shared memory, message passing, or pipes? I am not asking for a solution, but rather, if anyone knows,

SQL Server Custom Identity Column

送分小仙女□ 提交于 2019-12-24 15:31:13
问题 I want to generate a custom identity column related to type of product. Can this query guaranty the order of identity and resolve concurrency. This is a sample query: BEGIN TRAN INSERT INTO TBLKEY VALUES((SELECT 'A-' + CAST(MAX(CAST(ID AS INT)) + 1 AS NVARCHAR) FROM TBLKEY),'EHSAN') COMMIT 回答1: Try this: BEGIN TRAN INSERT INTO TBLKEY VALUES((SELECT MAX(ID) + 1 AS NVARCHAR) FROM TBLKEY WITH (UPDLOCK)),'EHSAN') COMMIT When selecting the max ID you acquire a U lock on the row. The U lock is