|
I have 2 threads and a shared float global. One thread only writes to the variable while the other only reads from it, do I need to lock access to this variable? In other words:
volatile float x; void reader_thread() { while (1) { // Grab mutex here? ...
Started by Daniel Dickison on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
I'm not sure how large float is in your environment, but it might if a float is the same size as an int on your architecture, what you could do is make your global variable course of action....
I would lock it down.
Use a lock.
|
|
I'm responsible for developing a large Python/Windows/Excel application used by a financial institution which has offices all round the world. Recently the regulations in one country have changed, and as a result we have been told that we need to create...
Started by Salim Fadhley on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Failing that, someone with knowledge of Python's and a code signature stashed... .
Usually the best option is to ensure the user running the app has limited potential damage is at least limited to that environment.
It hard to lock things down.
|
|
Dear ladies and sirs.
This question is in continuation of this one . The deal is simple.
Given:
A collection of lazily created singletons. Multithreaded environment. Wanted:
An implementation with as little lock penalty as possible when an already created...
Started by mark on
, 11 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
An itanium processor will allocate the memory of the variable and set the variable BEFORE....
lock(syncRoot) if(!singletons.ContainsKey) singletons[key] = new ...(); return singletons[key from that, very common initialization pattern).
|
Ask your Facebook Friends
|
Hello,
I have detected a memory corruption in my embedded environment (my program is running on a set top box with a proprietary OS ). but I couldn't get the root cause of it. the memory corruption , itself, is detected after a stress test of launching...
Started by Mohamed on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Along the same lines, try holding the lock to the shared memory region for an absurd length.
Snapshots of this data too, you perhaps can log the culprit grabbing the lock before corrupting your data.
|
|
In C, how to configure the initial settings for some program, using key-value pairs, with any or all of: a plain text configuration file , environment variables, and options on the command line. Also, how to decide which method's values overide those ...
Started by Rob Kam on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Arguments might affect the interpretation of config files or environment variable, but you still) Handle config files and environment variable (what order?) Re-run the command line to override all generally commandline argument....
|
|
Hi
WorkAround:
I have declared a class level Public static variable and initialized with a value 0 in the environment of ASP.NET 3.5 In load event I Incremented by 1 of that variable
Problem: 1).After getting page refresh and even Postback, I am getting...
Started by karthik on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
It will survive many browser sessions until you restart the web server (IIS) or until it restarts on its own (when it decides it needs to refresh its used resources)... .
Static variables keep their values for the duration of the application domain.
|
|
I have one std::list<> container and these threads:
One writer thread which adds elements indefinitely.
One reader/writer thread which reads and removes elements while available.
Several reader threads which access the SIZE of the container (by ...
Started by David Alfonso on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
To overcome this, you could define a new variable
volatile unsigned int ContainerSize = 0;
Update the....
Someone mentioned a RW lock, this is a good thing calculate the size when called.
A second element is being added, or vice-versa.
|
|
What is the most evil or dangerous code fragment you have ever seen in a production environment at a company? I've never encountered production code that I would consider to be deliberately malicious and evil, so I'm quite curious to see what others have...
Started by God of Data on
, 21 posts
by 21 people.
Answer Snippets (Read the full thread at stackoverflow):
"); Really Horrific Array/Variable names ( Literal example ):
foreach( $variablesarry before I realised they wern't the same....
Register Globals Variable Variables Inclusion of remote files and code via include("http:// ...
At once.
|
|
Reading this DZone article about Java concurrency I was wondering if the following code:
private volatile List list; private final Lock lock = new ReentrantLock(); public void update(List newList) { ImmutableList l = new ImmutableList().addAll(newList...
Started by teto on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
In general, I think you are better off using an AtomicReference instead of a volatile variable, both of those code samples behave....
In this very specific example, I think you would be OK with no locking on the variable reassignment.
|
|
The short of it is: Is it costly to check an Application Variable such as Application("WebAppName") more 10-20 times each time a page loads?
Background: (feel free to critique)
Some includes in my site contain many links and images which cannot use relative...
Started by Matias Nino on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Longer the lock keyword), so if you are only reading from the collection it will be as fast as a hash table, store it to a local variable....
I would say it does not matter.
Short answer - measure it and decide on your own environment.
|