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)
{
...
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...
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...
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' ...
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?
...
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...
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...
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? I need an explanation or a tutorial.
...
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);
}
}...
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...
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
...
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...
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...
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...
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...
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...
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...
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...
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?
...