I am trying to learn how to use rand_r, and after reading this question I am still a little confused, can someone please take a look and point out what I'm missing? To my understanding, rand_r takes a pointer to some value (or a piece of memory with some initial value) and use it to generate new numbers every time it is called. Each thre...
I need to create a thread safe list of items to be added to a lucene index.
Is the following thread safe?
public sealed class IndexQueue
{
static readonly IndexQueue instance = new IndexQueue();
private List<string> items = new List<string>();
private IndexQueue() { }
public static IndexQueue Instance {
get { ...
I've been reading up on multithreading and shared resources access and one of the many (for me) new concepts is the mutex lock. What I can't seem to find out is what is actually happening to the thread that finds a "critical section" is locked. It says in many places that the thread gets "blocked", but what does that mean? Is it suspende...
I have a bit of code that I've been trying to examine for thread safety. I'm using the basic lazy singleton model found here. I was wondering if it is still thread safe if I'm putting the instance in the HttpApplicationState object. I need to access this instance across all instances of the web application, so if this is not thread sa...
I think the title is clear.
...
Is this a safe way of iterating ConcurrentQueue<T>?
while (cq.GetEnumerator().MoveNext())
{
IIndexTask task;
if (cq.TryDequeue(out task))
task.Execute(service);
}
...
Hello.
There is a State Machine with two Transitions in the same function.
static readonly object _object = new object();
lock (_object)
{
// I want Host received the event of SMTrans01 first .
Obj.StateMachine.Send((int)MyStateMachine.EventType.SMTrans01, new object[2] { Obj, MyStateMachine.EventType.SMTrans01 });
}
lock (_o...
I made a c extension out of a python script that was fairly labour intensive. The code itself is well tested and simple. The c extension is called with a few large lists, and it then performs some clever arithmetic and returns a few new lists. The c extension is 100% self sufficient, it doesn't use any other c functions nor does it use a...
Hello! I have a simple class that looks a bit like this:
@protocol Recorder
@property(BOOL) isRunning;
- (void) start;
- (void) stop;
@end
And the method implementations:
- (void) start {
if (running)
return;
…
running = YES;
}
- (void) stop {
if (!running)
return;
…
running = NO;
}
And I st...
In a single-threaded application I use code like this:
Interface
function GetNextUID : integer;
Implementation
function GetNextUID : integer;
const
cUID : integer = 0;
begin
inc( cUID );
result := cUID;
end;
This could of course be implemented as a singleton object, etc. - I'm just giving the simp...
Hi
I am working in windows 7 phone based app using silverlight. I have following methods in one of my UI classes, GameScreen.xaml. I am calling startTimer method in the constructor GameScreen. Problem is that when the updateTime method is called and
timeLabel.Text = "Time left: 00 : " + time;
line is executed, the program throws Una...
first:
10-26 17:43:07.454: WARN/dalvikvm(6371): threadid=3: unable to interrupt threadid=19
10-26 17:43:07.487: DEBUG/dalvikvm(6371): GC freed 279 objects / 259776 bytes in 208ms
10-26 17:43:07.487: WARN/WindowManager(2215): Attempted to add application window with unknown token HistoryRecord{46366130 spexco.hus.cepvizyon/.ViewCam}. Ab...
I have a function which determines if an array needs to be smoothed. I have multiple arrays that this operation needs to be preformed on. I'd like to use the sections construct in OpenMP to do this. Unfortunately, I'm running into segmentation faults as soon as the code grows in an appreciable size. This may be a memory limitation is...
I was browsing through the code of Vosao CMS, an open source CMS hosted on Google App Engine (which I think is an awesome idea), and I stumbled upon the following code inside the CurrentUser class:
/**
* Current user session value cache class. Due to GAE single-threaded nature
* we can cache currently logged in user in static property...
I have been spending some time in debugging a programme which gives segmentation fault. The bug is quite indeterministic and intermittent, which is annoying. I narrowed it down to the calling of strtok. I suspect that it is the calling of strtok to split string in two different threads that causes the segmentation fault. Can I call strto...
Hi all,
I have doubt on thread Life cycle in android.This is my scenario I have downloaded data from web and stored it in the DB.all this activity i have done using thread,once the activity finished i passed the object to handler and proceed .
But my doubt is whether i need to stop the thread?
This is the Example
s...
My question concerns safe publication of field values in Java (as discuessed here http://stackoverflow.com/questions/801993/java-multi-threading-safe-publication).
As I understand it, a field can be safely read (meaning access from multiple threads will see the correct value) if:
read and write are synchronized on the same monitor
fie...
Lets assume I have such code for testing.
public class SimpleScheduler
{
public Script Script { get; set; }
private Thread _worker;
public void Schedule()
{
this._worker = new Thread(this.Script.Execute);
this._worker.Start();
}
public void Sleep()
{
//?
}
}
SimpleScheduler ju...
I know that some database drivers and other libraries providing connection to external services are incompatible with coroutine-based network libraries. However, I couldn't find out if SQLAlchemy can be safely used with such libraries (namely, gevent), and if any workarounds should be applied to exclude possible errors.
Can you either t...
In Qt, there is a nice idiom to have each object associated with a thread, so that all its event handlers will only run in that thread (unless called directly, of course).
Is there anything even remotely like that in C#/.NET? If not, how would you start writing your own?
Example:
// threaded.h
#include <QThread>
#include <QDebug>
#in...