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(...
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+" "...
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 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.
...
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 ...
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...
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...
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.
...
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 ...
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...
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...
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 ...
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...
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:...
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...
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...
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...
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 ...
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...
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?
...