multithreading

C# Stopwatch shows incorrect time

I have seen other user posts which show Stopwatch measuring time spent in "Thread.Sleep(5000)" to be around 5000ms. But my program produces the following results for (int i = 0; i < 20; ++i) { Stopwatch sw = Stopwatch.StartNew(); DateTime start = DateTime.Now; Thread.Sleep(5000); ...

Producer Consumer Chain and Thread Scheduling in .net

I've made a chain of 4 producer-consumer threads (forming a 4 step pipeline). To my amazement, all four threads are running in sequence, instead of concurrently!!! That is, the second thread mysteriously waits until the first thread is entirely done producing. The third thread mysteriously waits until the second thread is entirely done...

What advantages does Scala have over Java for concurrent programming?

How can scala make writing multi-threaded programs easier than in java? What can scala do (that java can't) to facilitate taking advantage of multiple processors? ...

NetBeans / Java / New hint: Thread.sleep called in loop

In NetBeans, there's a new hint that says: Thread.sleep called in loop. Question 1: How/when can it be a problem to sleep in a loop? Question 2: If it's a problem, what should I do instead? UPDATE: Question 3: Here's some code. Tell me in this case if I should be using something else instead of Thread.Sleep in a loop. In short, this i...

android splash screen/ loading screen.

I have a splash screen/loading screen that has .setVisibility() to GONE right after the draw call of my large bitmap is completed. The problem is the splash screen takes a bit to popup which i believe is due to the main activity booting up and doing CPU intensive applications on first run. Is there a way to get my splash screen displayed...

How does Thread.sleep() work when called from multiple threads.

Hi, sleep() is a static method of class Thread. How does it work when called from multiple threads. and how does it figure out the current thread of execution. ? or may be a more generic Question would be How are static methods called from different threads ? Won't there be any concurrency problems ? ...

C# - Is "volatile" really needed as a keyword?

As I read deeper and deeper into the meaning of the volatile keyword, I keep saying to myself "this is way into implementation, this should not be a part of a high level programming language". I mean, the fact that CPUs cache the data should be interesting for the JIT compiler, not to the C# programmer. A considerable alternative might ...

Working with database in the OnExecute event (Indy)

Hi , i have a server with these codes : procedure TFrmMain.TCPServerExecute(AContext: TIdContext); begin Res := DoRegister(Name,Family,Username,Password); end; function TFrmMain.DoRegister(Name,Family,Username,Password:string): bool; var Qry: TSQLQuery; begin Qry := TSQLQuery.Create(nil); try Qry.SQLConnection := FrmCon...

DoDragDrop() from another thread

Every time i want let the user to drag an control, i calling DoDragDrop of that control. The drag & drop works fine, but i have problem with things around: DoDragDrop completely blocking the form, no timer events jumps, no paint messages handled. DoDragDrop blocking not only for the drag & drop operation, but until target program fini...

cancel dialog after 3 seconds - keeps crashing my app after multiple uses

I have an extended dialog class that I want to show for 3 seconds then disappear. This works great the first 2 times it's called, but then it crashes my app after that. Admittedly, I'm not the best with threads and I think that's where my problem might be. As you can see from the code below (commented out section), I tried using a can...

concurrent programming in java

I have 2 threads running in paralel. The run function of the threads is as follows public void run(){ Runtime rt = Runtime.getRuntime(); Process s; try { s = rt.exec("cd /.../somefolder/"+i+"/"); closeStream(s); // this closes process s s = rt.exec("sh adapMs.sh"); closeStream(s); // this closes proc...

is there a limit to the number of threads that ruby can run at once?

if not whats the maximum while still remaining efficient? im creating 14 threads, each of which opens a list of URLs(about 500) creates a new thread for each one, which then downloads it, and adds it to a MySQL db. The MySQL pool size is set to 50. This is a rake task in RoR Would this work better using Kernal#fork or some other met...

Windows port/implementation for GNU Pth (Gnu Portable Threads)

I have inherited a pure C project that uses GNU Pth ( http://www.gnu.org/software/pth/ ) and I was hoping that there was a Windows port/implementation so I wouldn't have to stick a whole bunch (more) conditionals into my code. I know I am being hopeful, but is there anything that provides the exact same function signatures and functiona...

Connection Pooling over New Connection instance per Thread (JDBC)

Hi, I am creating a multi-threaded application. However, I have experienced lots of unexpected behavior from my application when I have one connection object serving all threads. I am in a dilemma. Should I let every thread create, use and dispose its own connection object or should I use a connection pool? I have tried connection po...

ClosedByInterruptException not thrown

The JDK docs say, that if a thread is interrupted that currently blocks in an io operation of an InterruptibleChannel, the channel is closed and a ClosedByInterruptException is thrown. However, i get a different behaviour when using a FileChannel: public class Main implements Runnable { public static void main(String[] args) throws Exc...

Can I Use Boost Message Queues for Thread Communication

Hi, I am spawning multiple worker threads from a main thread. Can I create message_queue for each thread from the main thread and send messages from the main thread. Am I asking this because message queues are meant for interprocess communication. Do I need to consider anything specific regarding this ...

How do I stop a thread when my winform application closes

Hello, I have a singleton that has a running thread for obtaining records from a server. But when I stop my winform application the thread keeps running. I have tried to create a destructor in my singleton to abort the thread if it running, but it does not have any effect on the thread - I know that the destructor is being evoked. I am...

Servers and threading models

Hi, I am troubled with the following concept: Most books/docs describe how robust servers are multithreaded and that the most common approach is to start a new thread to serve each new client. E.g. a thread is dedicated to each new connection. But how is this actually implemented in big systems? If we have a server that accepts requests...

Java threading objects

I've created an object of arrays with a size of 1000, they are all threaded so that means 1000 threads are added. Each object holds a socket and 9 more global variables. The whole object consists of 1000 lines of code. I'm looking for ways to make the program efficient because it lags. CPU use is at 100% everytime I start the program. ...

TNonblockingServer, TThreadedServer and TThreadPoolServer, which one fits best for my case?

Our analytic server is written in c++. It basically queries underlying storage engine and returns a fairly big structured data via thrift. A typical requests will take about 0.05 to 0.6 seconds to finish depends on the request size. I noticed that there are a few options in terms of which Thrift server we can use in the c++ code, speci...