multithreading

Non-blocking stdio

I'm working on a program which will be taking in user input from the console as well as printfing out in a separate thread. I want to avoid situations where the user is halfway through typing something in and a printf comes along and prints itself at the cursor. Is there a way to do non-blocking io in c from the console window? Ideally,...

Can I lock(something) on one line in C#?

Will the _otherThing field below be protected by the locks? class ThreadSafeThing { private readonly object _sync = new object(); private SomeOtherThing _otherThing; public SomeOtherThing OtherThing { get { lock(_sync) return _otherThing; } } public void UpdateOtherThing(SomeOtherThing otherThing) { lock(_...

GWT, Google App Engine, TimerTask or Thread in ServiceImpl throw exception.

I am using GWT and Google App Engine. I have array of records and I want to update them every 30 mins. In the ServiceImpl I have the fallowing code : new Timer().schedule(new TimerTask(){ @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } res...

Main thread waiting on background threads that update the interface

Right, my application occassionally kicks off a background thread that does some stuff. As its doing its stuff it also updates a progress bar on the main window. It does this by calling Invoke to get the main thread to update the interface. When the user closes the application, I want to wait until all the background threads are finis...

.NET SynchronizationContext - Which thread does it Send/Post to?

I'm planning on using the SynchronizationContext class to perform some cross-thread marshalling of UI updates. The idea is to avoid having to have a reference to the main form (i.e. the one in Application.Run(form)) just so I can say mainForm.BeginInvoke(); However, one thing that isn't clear from the documentation, is that when you ca...

Threadsafe and generic arraylist in c #?

Hello community, I want to have a generic thread safe collection and I saw that the Arraylist can easily be used thread safe by its static Synchronized method but what bugs me is that this ArrayList is not generic so when I want to use my objects I always have to cast them. Is there an easier way to do this? Also other list types would ...

java thread blocking

Can non synchronized methods called from synchronized methods allow a thread to block? public synchronized void foo(){ someStuff(); someMoreStuff(); bar(); } public void bar(){ //... does some things } If a thread is executing foo() is there anyway to ensure that bar() will be called before the thread sleeps? TIA ...

.Multithreading net - implement selected code without being interrupted by threads

SO users, I have 3 threads running simultaneously at any given time, trouble is after thread 1 tries to connect to a server by passing a username to it thread 2 is being invoked and by the time its thread 1's turn the server closes its connection on the code. Is there anywhere I can implement sending username and password simultaneousl...

Relationship between ManagedThreadID and Operating System ThreadID

I'm working on a multi-threaded C# Windows application that makes frequent calls into a native dll. These are blocking calls which can sometimes last quite a long time. In certain situations, I'd like to cancel these blocking calls on some worker threads from the main thread The native API I'm using provides a function for this purpo...

C# Threading/Lock confusion

I have the following code: var items = new List<string> {"1", "2", "3"}; // 200 items foreach(var item in items) { ThreadPool.QueueUserWorkItem((DoWork), item); } private void DoWork(object obj) { lock(this) { using(var sw = File.AppendText(@"C:\somepath.txt") { sw.WriteLine(obj); } } } Because of the thread...

Why can't we change apartment state of a ThreadPool thread and why don't we require a messagepump when ShowDialog is used?

Recently, I encountered this situation where I wanted to display a form on another thread (not the main/UI thread). I used a threadpool thread. The form hosted a RCW (for a COM component). Instantiating the form gave me an exception that the thread must be a STA. I tried to set the apartment state as STA. But, that didn't work either. I ...

Is "while (true)" usually used for a permanent thread?

I'm relatively new to coding; most of my "work" has been just simple GUI apps that only function for one thing, so I haven't had to thread much. Anyway, one thing I'm wondering about threading is if you want to keep a thread alive forever to do whatever job it's doing (processing, waiting for input, whatever), is it normal to format it ...

C# How can I force Localization Culture to en-US for whole applicaiton.

I'm having an issue with some byte conversions and a few of my calcualtions in one of my applications. I was able to contribute it to the person running it having an Italian Culture setting in windows. So my question is: What is the best way to for "en-US" on any computer running my application. I have a code sample below, but I am un...

What is the significance of the initial value of a semaphore?

A semaphore is a mechanism for avoiding race conditions. But what's the significance of the initial value of a semaphore? Say that a semaphore has an initial value of 5, is it that 5 processes can access some shared resource simultaneously? ...

How to set a time limit on a java function running a regex

I am running a regex in a java function to parse a document and return true if it has found the string specified by the regex and return false if it hasn't. But the problem is that when the document doesn't contain the string specified by the regex It takes a very long time to return false and I want to terminate that function if it take...

Are Thread.stop and friends ever safe in Java?

The stop(), suspend(), and resume() in java.lang.Thread are deprecated because they are unsafe. The Sun recommended work around is to use Thread.interrupt(), but that approach doesn't work in all cases. For example, if you are call a library method that doesn't explicitly or implicitly check the interrupted flag, you have no choice but...

Using Clipboard.GetDataObject() from a .Net worker thread.

Hi; To invoke Clipboard.GetDataObject(), your thread must be running in a single thread appartement (STA). My application uses a lot of asynchronous operation (Begin/End). The completion methods for those operations are called in a worker MTA thread. Once a thread starts running, I can't modify its thread appartement. What are the opt...

Piping output of subprocess.call to progress bar

I'm using growisofs to burn an iso through my Python application. I have two classes in two different files; GUI() (main.py) and Boxblaze() (core.py). GUI() builds the window and handles all the events and stuff, and Boxblaze() has all the methods that GUI() calls. Now when the user has selected the device to burn with, and the file to...

Debugging multi-threaded Python with Wing IDE

I'm debugging a multi-threaded Python program with Wing IDE. When I press the pause button, it pauses only one thread. I've tried it ten times and it always pauses the same thread, in my case called "ThreadTimer Thread", while the other threads keep on running. I want to pause these other threads so I could step with them. How do I do t...

Using multithreading for making queries in Delphi

I've been recently applying threads for making queries to a MYSQL database, I use MyDAC for connection to DB, 'cause TMyConnection doesnot let making simultaneously queries per a connection, I create a new connection and a new query object per every thread executing a query, so in certain time could happens that server has several connec...