multithreading

Howto access thread data outside a thread

Deadly 提交于 2020-01-16 03:42:09
问题 Question: I start the MS Text-to-speech engine in a thread, in order to avoid a crash on DLL_attach. It starts fine, and the text to speech engine gets initialized, but I can't access ISpVoice outside the thread. How can I access ISpVoice outside the thread ? It's a global variable after all... You find XPThreads here: http://www.codeproject.com/KB/threads/XPThreads.aspx #include <windows.h> #include <sapi.h> #include "XPThreads.h" ISpVoice * pVoice = NULL; unsigned long init_engine_thread

ThreadPoolExecutor - ArrayBlockingQueue … to wait before it removes an element form the Queue

假装没事ソ 提交于 2020-01-16 03:25:25
问题 I am trying to Tune a thread which does the following: A thread pool with just 1 thread [CorePoolSize =0, maxPoolSize = 1] The Queue used is a ArrayBlockingQueue Quesize = 20 BackGround: The thread tries to read a request and perform an operation on it. HOWEVER, eventually the requests have increased so much that the thread is always busy and consume 1 CPU which makes it a resource hog. What I want to do it , instead sample the requests at intervals and process them . Other requests can be

What's the source of thread-unsafety in this usage of pandas.Series.reindex(, copy=True)?

大兔子大兔子 提交于 2020-01-16 03:03:51
问题 Calling pd.Series.reindex is not thread safe (https://github.com/pandas-dev/pandas/issues/25870). My question is why is Series.reindex (which returns a copy and seems like a functionally pure operation) not thread safe, even when no-one is writing to that object's data? The operation I'm performing is: s = pd.Series(...) f(s) # Success! # Thread 1: while True: f(s) # Thread 2: while True: f(s) # Exception ! ... which fails for f(s): s.reindex(..., copy=True). So, why did the threaded call

How to return value from nested task in c++/cx?

我与影子孤独终老i 提交于 2020-01-16 02:33:11
问题 I have a bunch of threaded tasks like this after each other: create_task(somewinrtasyncfunction()).then([this(variable_that_the_last_task_returned) { //task here return info; }).then([this](info) { //another task here return status}); Now I want to use status outside the tasks, in the function that called it. How would I access it? 回答1: You return the task (or value) created by create_task(...).then(...).then(...) . If you need to get the result synchronously, you can try calling .get() on

Kill Boost thread with another timeout thread

风格不统一 提交于 2020-01-16 02:02:24
问题 I want to end a thread WorkerThread after a certain amount of time has elapsed. I was thinking to use a second thread TimeoutThread for this, that changes a flag after 15 seconds so the other thread stops. Is there a more elegant way in boost to do this? #include <boost/thread.hpp> struct MyClass { boost::thread timeoutThread; boost::thread workerThread; bool btimeout = true; void run() { timeoutThread = boost::thread(boost::bind(&MyClass::TimeoutThread, this)); workerThread = boost::thread

C# lock free coding sanity check

限于喜欢 提交于 2020-01-16 01:42:09
问题 UPDATED : now using a read-only collection based on comments below I believe that the following code should be thread safe "lock free" code, but want to make sure I'm not missing something... public class ViewModel : INotifyPropertyChanged { //INotifyPropertyChanged and other boring stuff goes here... private volatile List<string> _data; public IEnumerable<string> Data { get { return _data; } } //this function is called on a timer and runs on a background thread private void RefreshData() {

Populate JList with threads

纵饮孤独 提交于 2020-01-16 01:12:12
问题 I want JList to be populated with multiple threads. I tried this way but jlist is empty. It would be good if jlist was updated on the fly There are two threads, the other one loads in anouther direction new Thread(new Runnable() { @Override public void run() { for(i=0; i<cells.size()/2; i++){ System.out.println("thread"); try{ HtmlPage p = client.getPage("https://tbilisi.embassytools.com/en/slotsReserve?slot="+cells.get(i).getAttribute("data-slotid")); pages.add(p); if(!p.getUrl().toString()

Should I use async await on UI Thread or Task.Run to process multiple files?

老子叫甜甜 提交于 2020-01-16 01:09:32
问题 I am writing an application in WPF using .NET 4.5. The application allows the user to select multiple files and import them. When this happens the application will parse text files and store the data into a database. The files can be very large so I want the UI to remain responsive and allow the user to do other things while this is happening. I'm new to asynchronous programming and would to know what the best approach would be? According to a Microsoft article... "The async and await

400 Http Errors Using Jsoup in Multithreaded Program

匆匆过客 提交于 2020-01-16 01:03:46
问题 I've created a program that parses html pages. I use jsoup connect function within a callable class inside ThreadPool. The problem is that I'm connecting to the same website and with a thread pool size of 5+, I get IO Exceptions - 400 errors. How do I not make that happen? 回答1: If you're getting a 400 HTTP response, check the content of the response for an error message. A 400 means a bad request of some kind: you didn't include all the required information or included malformed information.

How to make two thread communicate through handler?

旧街凉风 提交于 2020-01-16 00:54:36
问题 I have form that button can auto re-size their size when mouse hover on button and default their size when mouse is exited. It work normally first time but after i try it more than one time their size is enlarged that i can not control normally. ImageIcon ima=new ImageIcon("C:\\Users\\chen rina\\Pictures\\win.png"); ImageIcon icon; Thread thr; Runnable r=new Runnable() { @Override public void run() { int i=40; while(i!=80){ try{ Thread.sleep(20); Image scale=ima.getImage().getScaledInstance(i