multithreading

Pattern for concurrent cache sharing

ε祈祈猫儿з 提交于 2020-01-15 15:12:24
问题 Ok I was a little unsure on how best name this problem :) But assume this scenarion, you're going out and fetching some webpage (with various urls) and caching it locally. The cache part is pretty easy to solve even with multiple threads. However, imagine that one thread starts fetching an url, and a couple of milliseconds later another want to get the same url. Is there any good pattern for making the seconds thread's method wait on the first one to fetch the page , insert it into the cache

Call system() inside forked (child) process, when parent process has many threads, sockets and IPC

五迷三道 提交于 2020-01-15 15:08:12
问题 I have a program that have many threads. Some threads are TCP servers... Each server fires new threads to handle any new connections. Inside one of the threads that handles a single client, I call fork(). The child process calls setpgid() (to create a new group) and then system() (the function of C/C++ standard library). The parent process keeps taking naps (usleep() function) and checking a time limit. If the time limit is exceeded before child process returns from system(), the parent

Python3 Websockets / Multithreading issue

…衆ロ難τιáo~ 提交于 2020-01-15 14:17:42
问题 A little BG information on my application: I am writing an application to stream data from a python script to a webbrowser. I am planning on streaming the data using the WebSocket module in Python3. I am streaming large amounts of data and I want to be able to start and stop the streaming at the user's leisure. My initial plan is to have two python3 websocket servers running. One to recieve commands from the web page (The "commander") and one to stream the data based on the commands recieved.

Can't synchronize call to notify()

旧巷老猫 提交于 2020-01-15 12:30:09
问题 Forgive me, but i am not able to get a call on NotificationBuilder's notify() method. I have this code: timer.scheduleAtFixedRate( new TimerTask() { @Override public void run() { synchronized (this) { Builder notif = new NotificationCompat.Builder(c); notif.setContentIntent(contIntent) .setWhen(System.currentTimeMillis()) .setTicker("Notification ticker") .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Vinceri") .setContentText("Ha recibido una oferta de trabajo") .setAutoCancel(true)

Thread safe Map of Queues

不羁岁月 提交于 2020-01-15 12:24:28
问题 I want to implement a thread safe Map of Queues. I intent to start with an empty Map. If the key does not exist, I want to create a new Map entry with a new Queue. If the key does exist, I want to add to the Queue. My proposed implementation is as follows: import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; public class StackOverFlowExample { private final Map<String, ConcurrentLinkedQueue<String>> map = new ConcurrentHashMap

Progress reporting from background task

强颜欢笑 提交于 2020-01-15 12:15:37
问题 I have a background task that imports files into a database. I want the user to see what is currently happening (collecting files/ importing files), which file is currently processed and how far the task has progressed. How can I do this in an easy way? The interaction between Model and Controller is so close, that I could almost put the importing code into the window's code file and change the progress bar value etc. directly. What do you think? How would you solve this problem? 回答1: Use a

Pool only executes a single thread instead of 4, and how do I make it infinite?

大憨熊 提交于 2020-01-15 11:54:08
问题 So I am working on a little Python tool to stress test an API of application. I've got a pretty nice script using Threading, but then I read that it will require manual coding to maintain n number of concurrent threads (meaning, starting new ones as soon as old ones finish), and the suggestion here: How to start a new thread when old one finishes? is to use ThreadPool, I tried as follows: def test_post(): print "Executing in " + threading.currentThread().getName() + "\n" time.sleep(randint(1,

Interrupting BitmapFactory.decodeStream

◇◆丶佛笑我妖孽 提交于 2020-01-15 11:39:13
问题 Let's assume we have a worker thread which calls BitmapFactory.decodeStream with some connection stream, like this: Bitmap bitmap = BitmapFactory.decodeStream(new URL(imgUrl).openConnection().getInputStream(), null, someUnrelatedOptions); Now we need to terminate this thread immedietely in order to reclaim any memory that BitmapFactory has allocated. We can't wait for it to finish for too long, as the memory is required by UI thread. The example is simplified, so let's don't go into details

Multi threading on WIndows

我只是一个虾纸丫 提交于 2020-01-15 11:37:27
问题 using System; using System.Threading; // Simple threading scenario: Start a static method running // on a second thread. public class ThreadExample { // The ThreadProc method is called when the thread starts. // It loops ten times, writing to the console and yielding // the rest of its time slice each time, and then ends. public static void ThreadProc() { for (int i = 0; i < 10; i++) { Console.WriteLine("ThreadProc: {0}", i); // Yield the rest of the time slice. Thread.Sleep(0); } } public

Execute a statement after thread gets over

荒凉一梦 提交于 2020-01-15 11:28:06
问题 I am having a function where I have used a thread in c#.net. I am having a another function on the next line of that thread. But this function has to be called only after the thread gets executed. How can i do it ? Example.. Somefunction() { // thread //(thread started) add() (another function but need to be executed only tha above thread gets over) } 回答1: Use a BackgroundWorker and include the function call in the worker completeted event handler. var worker = new BackgroundWorker(); _worker