multithreading

Bitmap Factory animation using threads or async task

一曲冷凌霜 提交于 2020-01-24 17:44:12
问题 This question is a follow up on multiple question's that I asked on this forum on why an animation that I have been trying is not working. Just a brief on the previous questions: My animation works as an individual project of 2 classes, but will not work when included in my project containing multiple classes. All activities leading up to my animation activity were closed using "finish()" class The app never closes or freezes, the animation just doesn't play, but the intent occurs and the

Thread Synchronization - Synchronizing three threads to print 012012012012… not working

拈花ヽ惹草 提交于 2020-01-24 17:19:04
问题 I am trying to synchronize three threads to print 012012012012.... but it is not working correctly. Each thread is assigned a number which it prints when it receives a signal from main thread. There is something wrong with the following program which I am not able to catch. public class Application { public static void main(String[] args) { int totalThreads = 3; Thread[] threads = new Thread[totalThreads]; for (int i = 0; i < threads.length; i++) { threads[i] = new MyThread(i); threads[i]

Updating ObservableCollection from non UI thread

时光总嘲笑我的痴心妄想 提交于 2020-01-24 15:42:06
问题 I am working on a Windows 8 Store app. I have a timer that calls a delegate every two minutes and makes an async web request. The resulting data is added to an observablecollection that is bound to a UI element. Doing this throws an exception because the UI is being modified on a non UI thread. In other places in my code I have done this await Window.Current.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async () => { ui code here } But this is causing a crash with Window

Nested ArrayList.ParallelStream() in custom ForkJoinPool uses threads unevenly [duplicate]

若如初见. 提交于 2020-01-24 14:19:44
问题 This question already has answers here : Why does stream parallel() not use all available threads? (2 answers) Closed yesterday . I want to use my custom ForkJoinPool to have more parallelism with ArrayList.parallelStream() (by default it uses common pool). I do this: List<String> activities = new ArrayList<>(); for (int i = 0; i < 3000; i++) { activities.add(String.valueOf(i)); } ForkJoinPool pool = new ForkJoinPool(10); pool.submit(() -> activities.parallelStream() .map(s -> { try { System

Nested ArrayList.ParallelStream() in custom ForkJoinPool uses threads unevenly [duplicate]

天涯浪子 提交于 2020-01-24 14:19:17
问题 This question already has answers here : Why does stream parallel() not use all available threads? (2 answers) Closed yesterday . I want to use my custom ForkJoinPool to have more parallelism with ArrayList.parallelStream() (by default it uses common pool). I do this: List<String> activities = new ArrayList<>(); for (int i = 0; i < 3000; i++) { activities.add(String.valueOf(i)); } ForkJoinPool pool = new ForkJoinPool(10); pool.submit(() -> activities.parallelStream() .map(s -> { try { System

One thread counting, other thread does a job and measurement

别说谁变了你拦得住时间么 提交于 2020-01-24 14:10:32
问题 I would like to implement a 2 thread model where 1 is counting (infinitely increment a value) and the other one is recording the first counter, do the job, record the second recording and measure the time elapsed between. Here is what I have done so far: // global counter register unsigned long counter asm("r13"); // unsigned long counter; void* counter_thread(){ // affinity is set to some isolated CPU so the noise will be minimal while(1){ //counter++; // Line 1* asm volatile("add $1, %0" :

One thread counting, other thread does a job and measurement

て烟熏妆下的殇ゞ 提交于 2020-01-24 14:10:11
问题 I would like to implement a 2 thread model where 1 is counting (infinitely increment a value) and the other one is recording the first counter, do the job, record the second recording and measure the time elapsed between. Here is what I have done so far: // global counter register unsigned long counter asm("r13"); // unsigned long counter; void* counter_thread(){ // affinity is set to some isolated CPU so the noise will be minimal while(1){ //counter++; // Line 1* asm volatile("add $1, %0" :

Can I expand downloading images to several threads?

人盡茶涼 提交于 2020-01-24 13:22:56
问题 I had a problem with ListBox , which doesn't work fine with my collection (nested listboxes, non static size, etc). I tried DeferredLoadListBox, but it requires static height(not my variant). So, I tried ItemsControl with ScrollViewer , and it works realy good! I have smooth scrolling, no lags, its exactly what i needed. But! As I understand, ListBox download content dynamically, only when it need this content, and ItemsControl loads all the content in one time. And its a problem, because I

Can I expand downloading images to several threads?

那年仲夏 提交于 2020-01-24 13:22:16
问题 I had a problem with ListBox , which doesn't work fine with my collection (nested listboxes, non static size, etc). I tried DeferredLoadListBox, but it requires static height(not my variant). So, I tried ItemsControl with ScrollViewer , and it works realy good! I have smooth scrolling, no lags, its exactly what i needed. But! As I understand, ListBox download content dynamically, only when it need this content, and ItemsControl loads all the content in one time. And its a problem, because I

Why is a immutable pointer to a static immutable variable not Sync?

孤人 提交于 2020-01-24 13:06:28
问题 A static global C string (as in this answer) doesn't have the Sync trait. pub static MY_STRING: &'static *const u8 = "hello" as const *u8; // TODO: Simple assertion showing it's not Sync ;) Sync is described as The precise definition is: a type T is Sync if &T is thread-safe. In other words, there is no possibility of data races when passing &T references between threads. It seems like this is entirely readonly and has static lifetime, so why isn't it safe to pass a reference? 回答1: The