multithreading

Using CoInitialize in a Delphi thread

半世苍凉 提交于 2021-01-27 23:16:19
问题 I am using TIdHttp and TXMLDocument inside a thread in a Delphi program. Now I want to know: Do these classes use COM objects so I need to call CoInitialize and CoUninitialize in this thread? If yes, do I have to use these functions at the body of execute method or at all methods that use TIdHttp or TXMLDocument classes? 回答1: TIdHTTP has no COM dependency. TXMLDocument can have a dependency on COM. On Windows, out of the box it is a wrapper around Microsoft's MSXML ActiveX component, which

Concurrent.futures code ends up with “BrokenProcessPool”

北城余情 提交于 2021-01-27 22:34:02
问题 Yesterday I asked a similar question and somebody suggested me to use concurrent.futures and asyncio. What I want is skipping the file if it takes too long to process. Here is my code: import os, glob import time import asyncio from concurrent.futures import ProcessPoolExecutor @asyncio.coroutine def coro(loop, of, filename): ex = ProcessPoolExecutor(4) yield from loop.run_in_executor(ex, os.system, "\"C:\\P.exe\" -o {} {}".format(of, filename)) for folder, subfolders, filenames in os.walk

How to pass a ref parameter inside lambda expression? - Thread issue

泪湿孤枕 提交于 2021-01-27 21:26:54
问题 I have a method to be called. public void RecordConversation(ref ChannelResource cr) { VoiceResource RecordResource = TServer.GetVoiceResource(); RecordResource.MaximumTime = 6000; RecordResource.MaximumSilence = 6000; RecordResource.TerminationDigits = ""; } To call it in a thread Thread recordThread = new Thread(() => RecordConversation(ref ChanResource)); recordThread.Start(); Of course we get an error. Cannot use ref or out parameter 'ChanResource' inside an anonymous method, lambda

Call to “DisplayManagerGlobal.getDisplayInfo()” causes App Not Responding (ANR) in the app

a 夏天 提交于 2021-01-27 21:03:31
问题 Apparently, something in the application calls the method from different threads (both main and a binder thread) which causes an internal ANR. It happens quite frequently and I don't have an idea as to where it happens because I cannot reproduce it on emulators or the test devices that I have got. What the app does : It is an app locker application, which draws a full screen lock view on application overlay and asks for a password (pattern), which also supports fingerprint unlock mechanism.

Make use of all CPUs on SLURM

空扰寡人 提交于 2021-01-27 19:52:00
问题 I would like to run a job on the cluster. There are a different number of CPUs on different nodes and I have no idea which nodes will be assigned to me. What are the proper options so that the job can create as many tasks as CPUs on all nodes? #!/bin/bash -l #SBATCH -p normal #SBATCH -N 4 #SBATCH -t 96:00:00 srun -n 128 ./run 回答1: One dirty hack to achieve the objective is using the environment variables provided by the SLURM. For a sample sbatch file: #!/bin/bash #SBATCH --job-name=test

Can I use local variables inside a Parallel Foreach loop (without unintentionally rewriting the previous value)

情到浓时终转凉″ 提交于 2021-01-27 19:05:44
问题 So I am attempting to process records from a datatable one row at a time. I am new to multi-threaded environments and I was asked to use Parallel.Foreach Loop. I wanted to know how local variables are treated in a Parallel execution mode. Following is my code. Parallel.ForEach(dtReportData.Tables[0].AsEnumerable(), drow => { string strType = drow["type"]; //Based on this type, I am executing logic from a switch case. }); Now. I want to know if I can declare and assign value to the variable

Exception in thread QueueManagerThread - scikit-learn

荒凉一梦 提交于 2021-01-27 18:50:19
问题 When I set n_jobs=-1 I get error and if I set n_jobs equal big value (n_jobs=100), but if set smaller value (e.g. n_jobs=32), it works fine. I've tried reinstall scikit-learn and joblib packages, but to no avail. Also, it (n_jobs=-1) works fine previously, but suddenly go wrong. from sklearn import datasets from sklearn.model_selection import cross_validate, StratifiedKFold from sklearn.linear_model import RidgeClassifier iris = datasets.load_iris() iris_X = iris.data iris_y = iris.target skf

Problem with thread-safe queue?

泪湿孤枕 提交于 2021-01-27 18:26:20
问题 I'm trying to write a thread-safe queue using pthreads in c++. My program works 93% of the time. The other 7% of the time it other spits out garbage, OR seems to fall asleep. I'm wondering if there is some flaw in my queue where a context-switch would break it? // thread-safe queue // inspired by http://msmvps.com/blogs/vandooren/archive/2007/01/05/creating-a-thread-safe-producer-consumer-queue-in-c-without-using-locks.aspx // only works with one producer and one consumer #include <pthread.h>

pthread_cond_wait() and signal, the result depend on OS

二次信任 提交于 2021-01-27 18:02:49
问题 I am a beginner of multi-threaded programming, and now I know that when a signal was sent while waiting with pthead_cond_wait() , the result depends on the OS. Can somebody tell me how to know how the call was interrupted, and how to write portable code? #include <stdio.h> #include <signal.h> #include <pthread.h> void sigusr1_handler(int sig) { printf("signal called\n"); } int main() { int n; pthread_mutex_t mut; pthread_cond_t cond; struct timespec ts; signal(SIGUSR1, sigusr1_handler);

Java - Multi threading sound clips to play at same time

和自甴很熟 提交于 2021-01-27 17:50:48
问题 Problem; Only hearing one sound clip when executed. After one sound has played the other doesn't play & neither can play at the same time. Result; To be able to play 2 sounds at the same time. Code: import java.io.*; import javax.sound.sampled.*; public class ThreadPlay extends Thread { private String filename; // The name of the file to play private boolean finished; // A flag showing that the thread has finished private ThreadPlay(String fname) { filename = fname; finished = false; } public