concurrency

C# asynchronous LCD write

一曲冷凌霜 提交于 2021-01-28 21:05:32
问题 So I'm working on a project that involves a LCD screen that can update 60 times per second. It uses a BitmapFrame and I need to copy those pixels to a library that updates the screen. Currently I'm getting about 30-35 FPS which is too low. So I'm trying to use multi-threading but this creates a lot of problems. The DisplayController already creates a thead to do all the work on like so: public void Start() { _looper = new Thread(Loop); _looper.IsBackground = true; _looper.Start(); } private

Multiple goroutines access/modify a list/map

前提是你 提交于 2021-01-28 20:10:52
问题 I am trying to implement a multithreaded crawler using a go lang as a sample task to learn the language. It supposed to scan pages, follow links and save them do DB. To avoid duplicates I'm trying to use map where I save all the URLs I've already saved. The synchronous version works fine, but I have troubles when I'm trying to use goroutines. I'm trying to use mutex as a sync object for map, and channel as a way to coordinate goroutines. But obviously I don't have clear understanding of them.

Implementing a Starve method (“Unrelease”/“Hold”) for SemaphoreSlim

瘦欲@ 提交于 2021-01-28 18:41:49
问题 I'm using a SemaphoreSlim with a FIFO behaviour and now I want to add to it a Starve(int amount) method to remove threads from the pool, sort of the opposite to Release() . If there are any running tasks, they will of course continue until they are done, since for the moment the semaphore is not keeping track of what is actually running and "owes" the semaphore a release call. The reason is that the user will dynamically control how many processes are allowed at any time for a given semaphore

Strange behavior of StampedLock with Thread class

泄露秘密 提交于 2021-01-28 18:16:13
问题 I'm running this code in IntellijIDEA Community on Windows import static java.lang.Thread.sleep; public class Main { public static void main(String[] args) { StampedLock lock = new StampedLock(); Thread th = new Thread(() -> { long stamp = lock.tryOptimisticRead(); try { System.out.println("Optimistic Lock Valid: " + lock.validate(stamp)); sleep(1); System.out.println("Optimistic Lock Valid: " + lock.validate(stamp)); sleep(2); System.out.println("Optimistic Lock Valid: " + lock.validate

Do multiple tasks while running code in actionperformed java

让人想犯罪 __ 提交于 2021-01-28 13:19:59
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

自作多情 提交于 2021-01-28 13:19:28
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

假如想象 提交于 2021-01-28 13:18:37
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Do multiple tasks while running code in actionperformed java

时光总嘲笑我的痴心妄想 提交于 2021-01-28 13:18:10
问题 Let's say i have a listener attached to a button. When i press this button, actionPerformed is called and i set a label as visible. Then the calculate() method runs(which has some really long calculations inside it and it takes time). Then i wanna print the results with the show() method. Thing is that i know for a fact that the label will be set as visible after all the code inside actionPerformed will be executed. So my question is : How should i set the calculate method to run on

Go func closure in loop

◇◆丶佛笑我妖孽 提交于 2021-01-28 12:40:54
问题 When executing the following code I get what I expect when the first loop is done (sequence from 0 to 9). But when the second loop finishes, the result is not what I expected (I expected the same result as in the first loop, but it prints only '10's): package main import ( "fmt" "sync" ) func main() { var wg sync.WaitGroup for i := 0; i < 10; i++ { wg.Add(1) go func(j int) { defer wg.Done() fmt.Println(j) }(i) } wg.Wait() fmt.Println("done first") for i := 0; i < 10; i++ { wg.Add(1) go func()

Using Golang to read csv, reorder columns then write result to a new csv with Concurrency

别等时光非礼了梦想. 提交于 2021-01-28 09:18:20
问题 Here's my starting point. It is a Golang script to read in a csv with 3 columns, re-order the columns and write the result to a new csv file. package main import ( "fmt" "encoding/csv" "io" "os" "math/rand" "time" ) func main(){ start_time := time.Now() // Loading csv file rFile, err := os.Open("data/small.csv") //3 columns if err != nil { fmt.Println("Error:", err) return } defer rFile.Close() // Creating csv reader reader := csv.NewReader(rFile) lines, err := reader.ReadAll() if err == io