multithreading

Does synchronize keyword prevent a thread from using its own variable while locked?

喜夏-厌秋 提交于 2020-01-25 04:24:06
问题 Lets take an example: public class DBServer { static boolean listening = false; private static ServerSocket serverSocket = null; private static Socket clientSocket = null; static List<ClientThread> users = null; public static void main(String[] args) { users= new LinkedList(); int portNumber = 0;//some valid port number System.out.println("Now using port number=" + portNumber); try { serverSocket = new ServerSocket(portNumber); } catch (IOException e) { System.out.println(e); } while

How to raise a static event thread safe in C#?

人走茶凉 提交于 2020-01-25 03:28:08
问题 Can i raise a static event thread safe? (i am not entirely sure what that even means.) The whole thing is part of an audio application, so i have (at least) the audio processing thread and the UI thread. The RaisePrintEvent gets invoked from unmanaged C code which processes the audio and other messages. The call to raise the event can happen from the audio processing thread and the UI thread. public static event ProcessPrint Print = delegate {}; private static void RaisePrintEvent(string e) {

Having thread-local arrays in cython so that I can resize them?

情到浓时终转凉″ 提交于 2020-01-25 02:46:04
问题 I have an interval-treeish algorithm I would like to run in parallel for many queries using threads. Problem is that then each thread would need its own array, since I cannot know in advance how many hits there will be. There are other questions like this, and the solution suggested is always to have an array of size (K, t) where K is output length and t is number of threads. This does not work for me as K might be different for each thread and each thread might need to resize the array to

How to parallelize many (100+) tasks without hitting global GCD limit?

谁说胖子不能爱 提交于 2020-01-25 01:25:10
问题 The problem : When lazy-loading a list of 100+ icons in the background, I hit the GCD thread limit (64 threads), which causes my app to freeze up with a semaphore_wait_trap on the main thread. I want to restructure my threading code to prevent this from happening, while still loading the icons asynchronous to prevent UI blocking. Context : My app loads a screen with SVG icons on it. The amount differs on average from 10-200. The icons get drawn by using a local SVG image or a remote SVG image

Multithreading refresh UI in Vaadin

混江龙づ霸主 提交于 2020-01-25 01:24:08
问题 I'm trying to implement a multithreading refresh UI in my Vaadin app. Part of this UI is a dChart based on container. To build dChart Im iterating through container and count elements by one of their properties, like this: Collection<?> itemIDS = container.getItemIds(); for (Object itemID : itemIDS) { Property property = container.getContainerProperty(itemID, "status"); String status = (String) property.getValue(); if (countMap.containsKey(status)) { countMap.put(status, countMap.get(status)

Multithreading: When to Start and Exit threads

∥☆過路亽.° 提交于 2020-01-25 00:15:11
问题 I am a little further along on this exercise and was not sure if I should post an answer with my updated code, edit my original post, or ask a new question. If I am not following protocol, please advise. What I have done so far is read in the input file and assigned all the integers to an array. I then divided the total number of integers ( index ) by the number of threads ( number_of_threads ) to find the optimal numbers_per_thread . I then create a while loop to increment through all the

How to check if thread finished execution Android Studio

安稳与你 提交于 2020-01-24 22:12:31
问题 I am trying to create an app that contains 2 spinners with data from a data base. When a button is pressed, a new intent is created, showing the 2 spinners. The problem is that I have to create the DB queries in a new thread, and when I run the app, I get a null pointer exception (as far as my understanding goes, it is because the array in which I store the DB data is not yet populated). My question is, how can I delay the creation of the spinners until the queries from the DB are made? Below

Thread safe creating and deleting file in Java

左心房为你撑大大i 提交于 2020-01-24 22:12:21
问题 Are methods Files.createFile() and Files.delete() thread safe? I have read in documentation that createFile() always an atomic operation but delete() is not. Should I somehow synchronize these blocks in my Java application and how? What atomic operation means for multihreading task? 回答1: a. What atomic operation means for multihreading task? In context of multi-threading atomicity is the ability of a thread to execute a task in such a manner so that other threads have apparently no side

How to use Thread to release the application from freezing in c#

淺唱寂寞╮ 提交于 2020-01-24 22:12:12
问题 I have the code below for scanning but When i press the button to start scanning, the windows form freezes and i can not move the form or minimizie/colse it until the process will be finished! i'm new in working with Thread but i tried to add Thread andi couldn't solve the problem. Does anyone know to where (how) can i write a Thread to release my form from freezing? Thanks. public Bitmap GetBitmapFromRawData(int w, int h, byte[] data) { //Do sth } //button to start the scan proccess private

How to use Thread to release the application from freezing in c#

社会主义新天地 提交于 2020-01-24 22:11:48
问题 I have the code below for scanning but When i press the button to start scanning, the windows form freezes and i can not move the form or minimizie/colse it until the process will be finished! i'm new in working with Thread but i tried to add Thread andi couldn't solve the problem. Does anyone know to where (how) can i write a Thread to release my form from freezing? Thanks. public Bitmap GetBitmapFromRawData(int w, int h, byte[] data) { //Do sth } //button to start the scan proccess private