multithreading

MFC/CCriticalSection: Simple lock situation hangs

I have to program a simple threaded program with MFC/C++ for a uni assignment. I have a simple scenario in wich i have a worker thread which executes a function along the lines of : UINT createSchedules(LPVOID param) { genProgThreadVal* v = (genProgThreadVal*) param; // v->searcherLock is of type CcriticalSection* while(1) { ...

Limiting one of each Runnable type in ExecutorService queue.

I have an Executors.newFixedThreadPool(1) that I send several different tasks to (all implementing Runnable), and they get queued up and run sequentially correct? What is the best way to only allow one of each task to be either running or queued up at one time? I want to ignore all tasks sent to the ExecutorService that are already in th...

Simple multi-threading - combining statements to two lines.

If I have: ThreadStart starter = delegate { MessageBox.Show("Test"); }; new Thread(starter).Start(); How can I combine this into one line of code? I've tried: new Thread(delegate { MessageBox.Show("Test"); }).Start(); But I get this error: The call is ambiguous between the following methods or properties: 'System.Threading...

Multithreading Errors in C#

Hi. I am trying to update a text box. I thought my threading code would fix the problem, but it does not. Can anyone help with this? new Thread((ThreadStart)delegate { txtCapacitance.Text = Math.Round(capacitance, 3).ToString(); }).Start(); Gives the following error: Cross-thread operation not valid: Control 'txtCapacitance' ...

Can multiple threads modify a dictionary?

In C#, can multiple threads read and write to a Dictionary provided each thread only accesses one element in the dictionary and never accesses another? ...

How to handle data output in an Observer?

I have an Observable and an Observer. The observable does download some stuff in a background thread and calls notifyObservers to let the observers read the status. At some point in public void update the observer tries to updates the GUI ((TextView)findViewById('R.id.foo')).setText("bar"); but it seems like the observable thread ca...

Problems related to showing MessageBox from non-GUI threads

I'm working on a heavily data-bound Win.Forms application where I've found some strange behavior. The app has separate I/O threads receiving updates through asynchronous web-requests which it then sends to the main/GUI thread for processing and updating of application-wide data-stores (which in turn may be data-bound to various GUI-eleme...

is it right to call ejb bean from thread by ThreadPoolExecutor?

I trying to call some ejb bean method from tread. and getting error : (as is glassfish v3) Log Level SEVERE Logger javax.enterprise.system.std.com.sun.enterprise.v3.services.impl Name-Value Pairs {_ThreadName=Thread-1, _ThreadID=42} Record Number 928 Message ID java.lang.NullPointerException at ua.co.rufous.server...

What is the difference between serialization and synchronization in java?

What is the difference between serialization and synchronization in java? I need an explanation or a tutorial. ...

Are memory barriers necessary for atomic reference counting shared immutable data?

I have some immutable data structures that I would like to manage using reference counts, sharing them across threads on an SMP system. Here's what the release code looks like: void avocado_release(struct avocado *p) { if (atomic_dec(p->refcount) == 0) { free(p->pit); free(p->juicy_innards); free(p); } }...

tiemout for a function that waits indefiinitely (like listen())

Hello, I'm not quite sure if it's possible to do what I'm about to ask so I thought I'd ask. I have a multi-threaded program where threads share a memory block to communicate necessary information. One of the information is termination of threads where threads constantly check for this value and when the value is changed, they know it's...

Is it possible or reasonable to implement the double-checked locking in Delphi?

As I known, there are two common kinds of practices to ensure the thread safety of lazy-initialization: Double-checked locking (Marks the variable as volatile to avoid the memory ordering) InterlockedCompareExchangePointer It seems VCL uses the second practice. Is there any reason? class function TEncoding.GetUTF8: TEncoding; var ...

How to tie a background thread to the lifetime of an object?

I want to create a background thread that's owned by an object. When that object is no longer needed, so is its background thread. pseudo code of what I currently have: ResetEvent _isCanceled ResetEvent _hasWork ThreadSafeQueue _workItems Init() new BackgroundThread(ThreadLoop).Start() AddWork(work) _workItems.Enqueue(work) _ha...

How to Lock a file and avoid readings while it's writing

My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return...

Can threads safely read variables set by VCL events?

Is it safe for a thread to READ a variable set by a Delphi VCL event? When a user clicks on a VCL TCheckbox, the main thread sets a boolean to the checkbox's Checked state. CheckboxState := CheckBox1.Checked; At any time, a thread reads that variable if CheckBoxState then ... It doesn't matter if the thread "misses" a change to th...

How can I stop my application?

I have the main thread from which I start a window using invokeLater. I run my application from command line. So, when application is running I see the window and my command line is "blocked" by the application. I can stop the application either by closing the window (as a result the command line is unblocked) or by typing Ctrl-C in the...

Why is my multithreaded Java program not maxing out all my cores on my machine?

Hi, I have a program that starts up and creates an in-memory data model and then creates a (command-line-specified) number of threads to run several string checking algorithms against an input set and that data model. The work is divided amongst the threads along the input set of strings, and then each thread iterates the same in-memor...

Core data, threads saving to a persistant store w/out locking, whats could go wrong?

My application downloads and caches photos into coreData in background threads while still allowing the user to poke around in the application. Currently after a photo's data is done downloading I start a thread to save it to coredata using the suggested shared storeCoordinator and thread-owned context then merge on the main thread, I a...

"Unhandled exception" error when mixing boost::thread with wxWidgets GUI.

Hello there, I was trying to access a wxDialog members from a boost::thread: void AnotherThread(myWxDialog *dlg) { wxMessageBox(dlg->TextBox1->GetValue(), "It works!"); // This throws an error } void myWxDialog::OnButtonClick(wxCommandEvent &event) { boost::thread myThread(AnotherThread, this); } And I got this error: Unhandled...

_REENTRANT Flag in pthreads

Hi, which compiling a multithreaded program we use gcc like below: gcc -lpthread -D_REENTRANT -o someprogram someprogram.c what exactly is the flag -D_REENTRANT doing over here? ...