Hi folks,
I have the following pseduo code in some Repository Pattern project that uses EF4.
public void Delete(int someId)
{
// 1. Load the entity for that Id. If there is none, then null.
// 2. If entity != null, then DeleteObject(..);
}
Pretty simple but I'm getting a run-time error:-
ConcurrencyException: Store, Update...
Hi
In previous question of mine, someone had meantioned that using Semaphores were expensive in C# compared to using a monitor. So I ask this, how can I replace the semaphore in this code with a monitor?
I need function1 to return its value after function2 (in a separate thread) has been completed. I had replaced the Semaphore.WaitOne ...
I did some search about this topic but found nothing valuable.
If I don't use PHP default session handler, there is no session lock at request level. So, I have to protect critical section by myself.
In Java, we have synchronized. In C#, we have lock.
In PHP, how to do that?
...
I have a simple producer/consumer scenario, where there is only ever a single item being produced/consumed. Also, the producer waits for the worker thread to finish before continuing. I realize that kind of obviates the whole point of multithreading, but please just assume it really needs to be this way (:
This code doesn't compile, but...
I'm looking at the TPL exception handling example from MSDN @
http://msdn.microsoft.com/en-us/library/dd537614(v=VS.100).aspx
The basic form of the code is:
Task task1 = Task.Factory.StartNew(() => { throw new IndexOutOfRangeException(); });
try
{
task1.Wait();
}
catch (AggregateException ae)
{
throw ae.Flatten();
}
My questi...
Hi,
According to an article on IBM.com, "a race condition is a situation in which two or more threads or processes are reading or writing some shared data, and the final result depends on the timing of how the threads are scheduled. Race conditions can lead to unpredictable results and subtle program bugs." . Although the article concern...
How do I prevent a race condition WITHOUT locking or using mutexes/semaphors in C++? I'm dealing with a nested for loop in which I will be setting a value in an array:
for (int i = 0; i < m; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < o; ++k)
array[k] += foo(...);
More or less, I want to deal with this so that I c...
I'm using JPoller to detect changes to files in a specific directory, but it's missing files because they end up with a timestamp earlier than their actual creation time. Here's how I test:
public static void main(String [] files)
{
for (String file : files)
{
File f = new File(file);
if (f.exists())
{
...
I have the following problem:
Our system has products that when released only are allowed to be purchased X times. Upon purchase a central purchasing algorithm checks how many Orders exist and if below X proceeds with the purchase.
In pseudoish C# code:
public class OrderMethods
{
public static Purchase(Product product, Client c...
I am creating a graphing calculator.
In an attempt to squeeze some more performance out of it, I added some multithreaded to the line calculator. Essentially what my current implementation does is construct a thread-safe Queue of X values, then start however many threads it needs, each one calculating a point on the line using the queu...
Hi.
Suppose that I have a method called doSomething() and I want to use this method in a multithreaded application (each servlet inherits from HttpServlet).I'm wondering if it is possible that a race condition will occur in the following cases:
doSomething() is not staic method and it writes values to a database.
doSomething() is stat...
Consider this situation:
Begin transaction
Insert 20 records into a table with an auto_increment key
Get the first insert id (let's say it's 153)
Update all records in that table where id >= 153
Commit
Is step 4 safe?
That is, if another request comes in almost precisely at the same time, and inserts another 20 records after step 2 ...
Hi, I'm relatively new with hibernate so please be gentle. I'm having an issue with a long running method (~2 min long) and changing the value of a status field on an object stored in the DB. The pseudo-code below should help explain my issue.
public foo(thing) {
if (thing.getStatus() == "ready") {
thing.setStatus("finishe...
I would like to safely be able to simulate open with O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW and O_CREAT | O_WRONLY | O_APPEND | O_NOFOLLOW on systems that do not support O_NOFOLLOW. I can somewhat achieve what I am asking for with:
struct stat lst;
if (lstat(filename, &lst) != -1 && S_ISLNK(lst.st_mode)) {
errno = ELOOP;
retu...
I have the following code
if (msg.position == 0)
//removed for brevity
else if (msg.position == txtArea.value.length)
//removed for brevity
else {
//ERROR: should not reach here.
errorDivTag.innerHTML += msg.position + " " + txtArea.value.length;
}
I'm having some really weird situations where I'm getting the error in ...
As a follow-up question to this one, I thought of another approach which builds off of @caf's answer for the case where I want to append to file name and create it if it does not exist.
Here is what I came up with:
Create a temporary directory with mode 0700 in a system temporary directory on the same filesystem as file name.
Open fil...
I'm curious about the following code:
class MyClass
{
public:
MyClass() : _myArray(new int[1024]) {}
~MyClass() {delete [] _myArray;}
private:
int * _myArray;
};
// This function may be called by different threads in an unsynchronized manner
void MyFunction()
{
static const MyClass _myClassObject;
[...]
}
Is there a p...
We have a composite wpf solution which use MVVM. there is a view class, in its code behind, we use a new worker thread to connect to a legacy system and load it into WindowsFormHost in xaml file using a third party app.
When user logon the solution, it tries to load three instances of view class on three tabs. sometimes we get "Windows ...
See this simple piece of code in PHP:
//Documentation:
//memcache_set ( string $key , mixed $var [, int $flag [, int $expire ]] )
//memcache_increment ( string $key [, int $value = 1 ] )
//part 1
memcache_set ( 'id' , 1 , 0 , 60 );
//part 2
$id = memcache_increment ( 'id' , 1 );
And now imagine that the incrementing "part 2" is call...
I have an ugly race condition with a WPF usercontrol, which is some kind of extended ComboBox:
The UserControl mainly defines two bindable DependencyProperties, one is the selected item, another one is a list, from which the selected item can be chosen.
Both are bindable, so the control may be initialized with or without a selected item ...