multithreading

how to get thread ID as integer on BSD in C/C++?

Does anyone know to get the current thread ID as an integer on BSD? i found this #ifdef RTHREADS 299 STD { pid_t sys_getthrid(void); } 300 STD { int sys_thrsleep(void *ident, int timeout, void *lock); } 301 STD { int sys_thrwakeup(void *ident, int n); } 302 STD { int sys_threxit(int rval); } 30...

Why is the pattern to update UI from a different thread not built into the .NET framework?

I know "why is my this framework like/not like xyz?" questions are a bit dangerous but I want to see what I'm missing. In WinForms, you can't update the UI from another thread. Most people use this pattern: private void EventHandler(object sender, DirtyEventArgs e) { if (myControl.InvokeRequired) myControl.Invoke(new Method...

Android how to solve problem with touching a View from the wrong thread?

I get the fault "CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views." The problem commes from the onDraw call in TutorialThread. The code works if the call to startAnimation in onDraw is removed. Why does the code work if startAnimation is removed? Why is this call different than t...

Java: How to run thread separately from main program/class?

Subj. How to run thread from main class BUT separately from that class? So a bit of details: I have one program which must run a process. That process (a cmd one) runs only when main program finished and unloaded from memory. And only after unload main program that process starting his work. What should I add to the program? ...

Unhandled FileLoadException that I think I'm handling

I have a thread that get I initialize like this: Utility.Log("1"); myThread = new Thread(new ThreadStart(delegate { Utility.Log("2"); and then the rest of the thread's execution. The weird thing is, despite that whole thing being wrapped in a try/catch, I'm only seeing a 1 in my log file (no 2), and I'm getting an unhandled Syste...

php memory overflow multi curl

Hi all, I have a PHP routine that I call shell_exec to traverse my own website and build an index. However since I do this multi-threaded I have been running into problems with memory storage...server memory spikes to 250MB then back down to 100MB randomly. I am constantly accessing the mysql database during this time; and the php sl...

CountDownTimer: "Can't create handler inside thread that has not called Looper.prepare()"

I know the general problem of "Can't create handler inside thread that has not called Looper.prepare()" has been asked before, but I am struggling to understand how it applies in this case. I am trying to construct a new CountDownTimer in a non-UI thread, which I guess is the cause of this error, but I don't really understand why the ...

Default IMarshal implementation?

I am trying to implement registry-free COM explicilty in my code (can't use registry-free COM via an app manifest since that only works on the exe level): I create a static class that loads the COM dll, calls DllGetClassObject, then IClassFactory::CreateInstance(). Works just fine to a point. Implementation details are at http://www.dim...

Unnecessary locking in STL? (Visual C++ Express)

I'm trying to build a Tetris AI algorithm that can scale over multiple cores. In my tests it turns out that using multiple threads is slower than using a single thread. After some research I found that my threads spend most of their time waiting for _Lockit _Lock(_LOCK_DEBUG). Here's a screenshot. As you can see, the lock is applied o...

Mutlithreading an OpenGL/WinAPI application

NOTE: Please read the whole thing before posting, you'll see why. So I have an OpenGL/WinAPI application. I'm doing what you would expect, by doing cycles of handling messages, then rendering a frame, handling messages, rendering frame... The trouble is, when I resize or move a window, the screen freezes, and it can look quite ugly. I ...

Problem using image files in Android

I am writing an Android app, which is basically a quiz. A it contains pictures of animals and the user must click on the correct picture. The pictures are all png files used as background pictures for button views. The problem I have/had is with the onCLick method. THis is the code. public void onClick(View view) { if(view == r1)...

ThreadQueue - Development for Servers - C++

Today i got a idea to make an ThreadQueue for C++, for my Server Application. unsigned int m_Actives; // Count of active threads unsigned int m_Maximum; std::map<HANDLE, unsigned int> m_Queue; std::map<HANDLE, unsigned int>::iterator m_QueueIt; In an extra Thread i would to handle these while: while(true) { if(m_Actives != m...

How to create threads in ASP.NET pages from CLR thread pool instead of ASP.NET pool ?

If I create a new thread on an ASP.NET page the IsThreadPoolThread property is true. First question is, is it from ASP.NET pool or CLR pool ? Second question is, if it is from ASP.NET pool then how to create a thread from CLR and don't use ASP.NET pool ? I need a synchronous solution for long-running requests (full story). ...

How to remove old queued tasks in ThreadPoolExecutor and insert new tasks instead?

I load a lot of images form internet with a ThreadPoolExecutor. When new images found, I need to render it first, in that case I want to abandon the old tasks which are still queued in the ThreadPoolExecutor and added these new items to download. I found there are no "clear queue" method in ThreadPoolExecutor, and "purge" method sounds...

C# Multithreaded application and SQL connections help...

I need some advice regarding an application I wrote. The issues I am having are due to my DAL and connections to my SQL Server 2008 database not being closed, however I have looked at my code and each connection is always being closed. The application is a multithreaded application that retrieves a set of records and while it processes...

Blackbox testing of multithreaded programs

I test of multithreaded program. But i dont want to use unit testing method. I want to use blackbox method in my testing work. I know that for testing of multithreaded application I have to use multicore processor, and give load for application and testing synchronization and locks between interfaces my program, but the bugs that I find...

Interview Question: When Control.InvokeRequired do you use Control.Invoke or Control.BeginInvoke?

I have had recently one of those really bad interviews, where they play good cop/bad cop with you. Whatever I replied wasn't good enough for one of them and my confidence was shrinking minute by minute. His final question that really confused me was the following: if a control would need InvokeRequired would there be a difference in doi...

COM Threading Model - Perpetual Confusion

Hi, I have been reading MSDN articles about COM Threading Model. In one of those (http://msdn.microsoft.com/en-us/library/ms687205%28VS.85%29.aspx), I came across following line: "Like other servers, in-process servers can be single-threaded, apartment-threaded, or free-threaded.". I am confused about what (COM Client thread and COM S...

Responding to httpRequest after using threading.Timer to delay response

Hey everyone, I'm trying to patch a testing framework built in python for javascript called mootools-test-runner (i'm a front end developer by day, so my python skills are pretty weak... really weak.) The use case is we want to be able to make a json request to the server and have it delay x amount of time before it returns -- original...

C# Cross Thread operation not valid

Hey, I am working on some code where I initialize an object (in this case a form), which then idles until it either receives a message from someone, or one of its methods is invoked directly. In my form, I have a listbox (lTester) that shows all calls made to this form. During run-time I get the following error: Cross-thread operat...