I need some help dealing with three Threads in Android
One thread is the main thread, the other is the GLThread, and the other is a WorkerThread I created to update the game state.
The problem I have is they all need to access the same LinkedList of game objects. Both the GLThread and my WorkerThread only read from the LinkedList, so ...
I am using the BlockingQueue code posted in this question, but realized I needed to use a Stack instead of a Queue given how my program runs. I converted it to use a Stack and renamed the class as needed. For performance I removed locking in Push, since my producer code is single threaded.
My problem is how can thread working on the (...
I'm new to threads. I'm using a 3rd party library that uses threads which at times call a procedure I've provided.
How do I update update a TLabel.Caption from my procedure when its called by the thread?
If I've called InitializeCriticalSection elsewhere, is it as simple as
EnterCriticalSection(CritSect);
GlobalVariable := 'New ...
MSDN says that public static members of System.Windows.Application are thread safe. But when I try to run my app with multiple threads I get the following exception:
ArgumentException: An entry with the same key already exists.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic....
The Application static members are supposed to be thread safe:
The public static (Shared in Visual
Basic) members of this type are thread
safe. In addition, the FindResource
and TryFindResource methods and the
Properties and Resources properties
are thread safe.1
How much can we trust that statement in a multithreaded env...
I still feel a bit unsafe about the topic and hope you folks can help me -
For passing data (configuration or results) between a worker thread polling something and a controlling thread interested in the most recent data, I've ended up using more or less the following pattern repeatedly:
Mutex m;
tData * stage; // temporary, ac...
Are the "modify" operators like +=, |=, &= etc atomic?
I know ++ is atomic (if you perform x++; in two different threads "simultaneously", you will always end up with x increased by 2, as opposed to x=x+1 with optimization switched off.)
What I wonder is whether variable |= constant, and the likes are thread-safe or do I have to protec...
My main concern is with the boolean flag... is it safe to use it without any synchronization? I've read in several places that it's atomic (including the documentation).
class MyTask
{
private ManualResetEvent startSignal;
private CountDownLatch latch;
private bool running;
MyTask(CountDownLatch latch)
{
run...
I've been reading the answer to a similar question, but I'm still a little confused... Abel had a great answer, but this is the part that I'm unsure about:
...declaring a variable volatile makes it volatile for every single
access. It is impossible to force this
behavior any other way, hence volatile
cannot be replaced with Int...
I know, it has been made quite clear in a couple of questions/answers before, that volatile is related to the visible state of the c++ memory model and not to multithreading.
On the other hand, this article by Alexandrescu uses the volatile keyword not as a runtime feature but rather as a compile time check to force the compiler into fa...
I'm clear on the usage of MemoryBarrier, but not on what happens behind the scenes in the runtime. Can anyone give a good explanation of what goes on?
...
There are lots written about the ReaderWriterLockSlim class which allows multiple read and a single write. All of these (at least that I had found) tell how to use it without much explanation why and how it works. The standard code sample is:
lock.EnterUpgradeableReadLock();
try
{
if (test if write is required)
{
lock.Enter...
public static MySingleton getInstance() {
if (_instance==null) {
synchronized (MySingleton.class) {
_instance = new MySingleton();
}
}
return _instance;
}
1.is there a flaw with the above implementation of the getInstance method?
2.What is the difference between the two implementations.?
public static synchronized MyS...
Hi,
Currently I have the following class:
public class PluginManager
{
private static bool s_initialized;
private static object s_lock = new object();
public static void Initialize() {
if (!s_initialized) {
lock (s_lock) {
if (!s_initialized) {
// initialize
...
Why is locking a type considered very bad?
For example, lock(typeof(DateTime)) I understand that static methods of any class in .net is considered thread safe, and that instance members are not. So it isn't necessary to lock DateTime while you are using it. The book I am reading doesn't explain why it is bad it just says it is. Any expla...
Hello I am writing some data structures in C, and I've realized that their associated functions aren't thread safe. The i am writing code uses only standard C, and I want to achieve some sort of 'synchronization'.
I was thinking to do something like this:
enum sync_e { TRUE, FALSE };
typedef enum sync_e sync;
struct list_s {
//Other ...
I've got a class with several properties. On every value update, a Store method is called which stores all fields (in a file).
private int _Prop1;
public int Prop1 {
get {
return _Prop1;
}
set {
_Prop1 = value;
Store();
}
}
// more similar properties here...
private XmlSerializer _Ser = new ...;...
The usual pattern for a singleton class is something like
static Foo &getInst()
{
static Foo *inst = NULL;
if(inst == NULL)
inst = new Foo(...);
return *inst;
}
However, it's my understanding that this solution is not thread-safe, since 1) Foo's constructor might be called more than once (which may or may not matter) and...
Hi, I'm seeing this code in a project and I wonder if it is safe to do:
(ASP.NET MVC 2.0)
class MyController
{
void ActionResult SomeAction()
{
System.Threading.Thread newThread = new System.Threading.Thread(AsyncFunc);
newThread.Start();
}
void AsyncFunc()
{
string someString = HttpContext.Request.UrlReferrer.Au...
So i've read around that instead of calling a event directly with
if (SomeEvent != null)
SomeEvent(this, null);
i should be doing
SomeEventHandler temp = SomeEvent;
if (temp != null)
temp(this, null);
Why is this so? How does the second version become thread safe? What is the best practice?
...