multithreading

BlockingCollection in Task Parallel Library does not automatically release the reference of the underlying instances

I use a BlockingCollection to implement a producer-consumer pattern in C# 4.0. The BlockingCollection holds items which take up quite a lot memory. I would like to let the producer takes one item out of the BlockingCollection at a time, and process it. I was thinking that by using foreach on BlockingCollection.GetConsumingEnumerable(...

Locking on Strings

2 Questions: str field is shared between two instance of A type [line 2] What's implications according to following code ? class A implements Runnable { String str = "hello"; // line 2. public void run(){ Synchronized(str){ System.out.println(str+" "+Thread.currentThread().getName()); Thread.sleep(100); System.out.println(str+" "...

Share one variable between threads ?

Hi everybody ! i have this scenario: class MyClass { Producer p; Consumer c; public static void main(String[] args){ BlockingQueue q = new LinkedBlockingQueue(); p = new Producer(q); c = new Consumer(q); Thread t = new Thread(p); t.start(); new Thread(c).start(); while ...

What happens to a Thread that fails to acquire a Semaphore?

What happens when a thread cannot acquire a Semaphore (due to lack of permit). Will it be moved to the wait state? EDIT:Will the thread start resume the previous execution sequence, when the semaphore becomes available. ...

GUI frozen while i update my ObservableCollection

I have a WPF application that displays an ObservableCollection. It's about 182 rows, and the object (let's call it PositionLight) inside the collection has about 70 properties to display. All calculation to input data in these properties are made in a second thread which will recalc everything every 20 secondes, and will send a List to ...

What is the difference between GCD Dispatch Sources and select() ?

I've been writing some code that replaces some existing: while(runEventLoop){ if(select(openSockets, readFDS, writeFDS, errFDS, timeout) > 0){ // check file descriptors for activity and dispatch events based on same } } socket reading code. I'd like to change this to use a GCD queue, so that I can pop events on to the queue...

Win32SerialPort Notification thread In javax.comm programming

Hi, all. I'm using the javax communication API to connect the serial port, and I can send and receive data with it. But there's a problem, when the main method is over, the program is still running. I tried debug mode and found that when executed "SerialPort.addEventListener(); notifyOnDataAvailable(true);", a Win32SerialPort Notificatio...

C++ Thread Pool

What is a good open source implementation of a thread pool for C++ to use in production code (something like boost)? Please provide either your own example code or a link to example code usage. ...

How To Pass refrence and Get Return in Thread?

Hello Guys, I Working on desktop application where i am get struck. I have a method through I am doing HTTP Post And Get. I am managing this object through ref in entire application. This object fetching category from website and i am using same ref for posting as well. This category Fetcher method return datatable of categories. This ...

Need help with threading -C# Winforms

I am trying to create a thread that contains a form progress bar(just a gif image) I have called the StartProgress right before a large method. Basically when the thread starts it loads up the ProgressBar form (which I want to show all the time, and just hide it when its not needed) and with ProgressActive to true, it should display the...

Launching threads from within while loop, what happens?

Hi, I want to have a while loop that launches a thread on each loop, I am using the following to launch the thread, do I need to have a unique identifier for each thread or becuase it is launching from different loops will it launch ok, or will it overwrite the previous launch as they are using the same identifier? while(x<y){ Runnable...

Matplotlib, Pylab using TKAgg: encountering PyEval_RestoreThread: NULL tstate when using plt.ion() on win32

EDIT: Bah, finally found a discussion on the Runtime Error, although it focuses on using PythonWin, which I did not have installed at the time. After installing PythonWin and setting up GTK (as per an earlier question), I was still encountering the error. The solution from the discussion board here was to append plt.close() after the ...

Resetting a Semaphore

What is the best way to reset a semaphore that have threads waiting on it. Right now all I can think of is just doing a while loop and releasing the semaphore until a semaphore full exception occurs. I'm not sure what is the best practice. semaphore.Close(); semaphore = new Semaphore(0,1); Or while(true) { try { semapho...

Detecting when a "new" item has been deleted

Consider this program: int main() { struct test { test() { cout << "Hello\n"; } ~test() { cout << "Goodbye\n"; } void Speak() { cout << "I say!\n"; } }; test* MyTest = new test; delete MyTest; MyTest->Speak(); system("pause"); } I was expecting a crash, but instead this happened:...

Terminate a sockert.recv in a thread in Python

Hello, To implement a simple protocol in python, I've used a thread to monitor acknowledgements send by the receiver. To do this, I use a thread in a function def ackListener(self): while self.waitingforack: ack = self.socket_agent.recv(4) ... exit() where self.waitingforack is a boolean I set to False when I...

Is there a prefered approach for introducing a delay before a WCF call

As my user changes the CurrentItem of a dataForm, I need to go the server to get addtional data. It's quite likely that the user could scroll through several items before finding the desired one. I would like to sleep for 500ms before going to get the data. Is there a component already in the SDK or toolkit like a background worker th...

Send updated data to background thread

I have a background thread that is sending data about the application's current status to a server. The thread is supposed to constantly - or at least whenever the status changes - send this data. The data is coming from the UI and the user is able to change the status any moment (by moving with the finger over the screen), so I need to...

Running a windows form in a separate thread.

I am dealing with running a control in a form, however the form itself is of no value to me. I essentially want the form to run a task and return a value, however for that I'd like to use something like an AutoResetEvent to return from the function call only when it has completed, which obviously would block the forms thread and make it ...

Ruby won't read /proc/mounts IFF in a thread and on RHEL 5.5

I've been successfully reading the Linux file '/proc/self/mounts' from within a Ruby thread using stock Ruby in Ubuntu Lucid (ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]). Now I'm trying to do the same on Red Hat 5.5 (ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]), but the thread won't complete. I wrote a testing script...

can threads contend over access to a single address?

Take a boolean value. One thread is trying to assign a pre-determined value to it, and at exactly the same time another thread is trying to read it. What happens? ...