473,738 Members | 5,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where are my threads blocking problems?

In the following code I simulate work being done on different threads by
sleeping a couple methods for about 40 ms. However, some of these methods
that should finish in about 40 -80 ms take as long as 2300 ms to complete.
This is fairly rare, but the test code below will definitely show it.

Somehow, I must not have my design right.

The idea of this code is that I do two different types of processing (
1-starting and 2-ending) based on unique ID numbers. For example, for ID #1,
I can do the start process or the end process, and I can do them in any
order (start doesn't have to be called before end in a particular slice of
time). The restriction is that I can't begin one of these processes while
the other one is in progress. In that case I have to wait. But only the
thead handling ID #1 processing (and only for the one blocked method) should
wait. Any other processing for other ID numbers should be able to proceed
without regard for the fact that ID #1 has to wait for one of its processes
to complete.

The two processes are called by different threads and I don't create those
threads (ASP.NET does).

(In case anyone wants to know what the practical use of this code is, it is
used in an ASP.NET app to initialize a session and then clean up/terminate a
session. ASP.NET reuses session numbers, so I have been forced to be sure
that I am do not begin initializing a session if that same session number is
in the process of being ended. The inverse situation also applies. However,
please direct any comments on ASP.NET sessions or session ID reuse to
another newsgroup topic. Thanks.)

I appreciate anyone pointing out design or implementation problems with this
code in regard to threading.

You can build this code as a C# console app and run it. It has a hard-coded
parameter in Main() determining how long it will run (loop over the tests).

(I apologize for the messy Main method that is used to start the testing.)

using System;
using System.Threadin g;
using System.Collecti ons;

namespace testing
{
/// <summary>
/// solution for cleaning up sessions where sessionID can be reused.
/// </summary>
public class SessionStarter
{
private const int waitTime = 4000;//used in TryEnter
private static bool keepTesting = true;
private static TimeSpan maxTime = TimeSpan.MinVal ue;
private static string maxMethodName = "none";

private class ActiveSession
{
public string SessionID;

public ActiveSession(s tring sessionID)
{
this.SessionID = sessionID;
}//ctor
}//struct ActiveSession

private static Hashtable sessionsBeingPr ocessed = new Hashtable();

private static void CheckForConflic tingSession(str ing sessionID, out
ActiveSession mySession)
{
DateTime start = DateTime.Now;
if (Monitor.TryEnt er(sessionsBein gProcessed, waitTime))
{
try
{
if (sessionsBeingP rocessed.Contai ns(sessionID))
{
mySession = sessionsBeingPr ocessed[sessionID] as ActiveSession;
Console.WriteLi ne(">>>>>>>>> " + Thread.CurrentT hread.Name + ": " +
sessionID + " is already being processed! <<<<<<<<<");
}
else
{
mySession = new ActiveSession(s essionID);
sessionsBeingPr ocessed.Add(ses sionID, mySession);
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + sessionID + "
added to sessionsBeingPr ocessed");
}
}
finally
{
Monitor.Exit(se ssionsBeingProc essed);
}
}
else
{
keepTesting = false;
Exception e = new Exception(Threa d.CurrentThread .Name + ": " +
"Exception: could not get lock on sessionsBeingPr ocessed for " + sessionID);
//log it
throw e;
}
TimeSpan ts = DateTime.Now - start;
if (ts > maxTime){ maxTime = ts; maxMethodName =
"CheckForConfli ctingSession";}
Console.WriteLi ne(Thread.Curre ntThread.Name + ":
CheckForConflic tingSession time: " + ts.TotalMillise conds);

}//CheckForConflic tingSession

public static void StartSession(st ring sessionID, int workAmount)
{
DateTime start = DateTime.Now;
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "entering
StartSession method: " + sessionID);
ActiveSession mySession;
CheckForConflic tingSession(ses sionID, out mySession);
HelpStartSessio n(sessionID, mySession, workAmount);
TimeSpan ts = DateTime.Now - start;
if (ts > maxTime){ maxTime = ts; maxMethodName = "StartSession"; }
Console.WriteLi ne(Thread.Curre ntThread.Name + ": StartSession time: " +
ts.TotalMillise conds);
}//StartSession

private static void HelpStartSessio n(string sessionID, ActiveSession
mySession, int workAmount)
{
bool entered2 = Monitor.TryEnte r(mySession, waitTime);
if (entered2)
{
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + sessionID + " is OK
to be initialized.");

try
{
//do all work
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "Starting session
" + sessionID + " initialization. ..");
Thread.Sleep(wo rkAmount);
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "Finished session
" + sessionID + " initialization. ..");
}
catch (Exception )
{
keepTesting = false;
Exception me = new Exception("Exce ption: Unable to complete session " +
sessionID + " initialization. ");
//log it
throw me;
}
finally
{
//Monitor.Pulse(m ySession);
sessionsBeingPr ocessed.Remove( sessionID);
Monitor.Exit(my Session);
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + sessionID + " is
unlocked by StartSession");
}
}
else
{
keepTesting = false;
Exception me2 = new Exception("Time d out. Could not get Monitor to start
sessionID " + sessionID);
//log it
throw me2;
}

}//HelpStartSessio n

public static void EndSession(stri ng sessionID, int workAmount)
{
DateTime start = DateTime.Now;
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "entering EndSession
method: " + sessionID);
ActiveSession mySession;
CheckForConflic tingSession(ses sionID, out mySession);
HelpEndSession( sessionID, mySession, workAmount);
TimeSpan ts = DateTime.Now - start;
if (ts > maxTime){ maxTime = ts; maxMethodName = "EndSession ";}
Console.WriteLi ne(Thread.Curre ntThread.Name + ": EndSession time: " +
ts.TotalMillise conds);
}//EndSession

private static void HelpEndSession( string sessionID, ActiveSession
mySession, int workAmount)
{
bool entered2 = Monitor.TryEnte r(mySession, waitTime);
if (entered2)
{

Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + sessionID + " is OK
to be terminated.");

try
{
//do all work
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "Beginning session
" + sessionID + " termination..." );
Thread.Sleep(wo rkAmount);
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + "Completed session
" + sessionID + " termination.");
}
catch (Exception e)
{
keepTesting = false;
//log it, etc.
throw e;
}
finally
{
//Monitor.Pulse(m ySession);
sessionsBeingPr ocessed.Remove( sessionID);
Monitor.Exit(my Session);
Console.WriteLi ne(Thread.Curre ntThread.Name + ": " + sessionID + " is
unlocked by EndSession");
}
}
else
{
keepTesting = false;
//log and throw exception
Exception ex = new Exception(Threa d.CurrentThread .Name + ": " + "Timed
Out. Could not get Monitor to end sessionID " + sessionID);
//log
throw ex;
}
}//HelpEndSession
public static void Main(string[] args)
{
SessionStarter ss = new SessionStarter( );

DateTime timeLimit = DateTime.Now.Ad dMinutes(120.50 15);

Thread startSessionThr ead;
Thread endSessionThrea d;
Thread startSessionThr ead2;
Thread endSessionThrea d2;
Thread startSessionThr ead3;
Thread endSessionThrea d3;
Thread startSessionThr ead4;
Thread endSessionThrea d4;
Thread startSessionThr ead5;
Thread endSessionThrea d5;

Random r = new Random();

while (keepTesting && DateTime.Now < timeLimit)
{
startSessionThr ead = new Thread(
new ThreadStart(ss. Start));
startSessionThr ead.Name = "startThrea d1";

endSessionThrea d = new Thread(
new ThreadStart(ss. End));
endSessionThrea d.Name = "endThread1 ";

startSessionThr ead2 = new Thread(
new ThreadStart(ss. Start2));
startSessionThr ead2.Name = "startThrea d2";

endSessionThrea d2 = new Thread(
new ThreadStart(ss. End2));
endSessionThrea d2.Name = "endThread2 ";

startSessionThr ead3 = new Thread(
new ThreadStart(ss. Start3));
startSessionThr ead3.Name = "startThrea d3";

endSessionThrea d3 = new Thread(
new ThreadStart(ss. End3));
endSessionThrea d3.Name = "endThread3 ";

startSessionThr ead4 = new Thread(
new ThreadStart(ss. Start4));
startSessionThr ead4.Name = "startThrea d4";

endSessionThrea d4 = new Thread(
new ThreadStart(ss. End4));
endSessionThrea d4.Name = "endThread4 ";
startSessionThr ead5 = new Thread(
new ThreadStart(ss. Start5));
startSessionThr ead5.Name = "startThrea d5";

endSessionThrea d5 = new Thread(
new ThreadStart(ss. End5));
endSessionThrea d5.Name = "endThread5 ";

Thread[] threads = new Thread[10];
int[] ordering = new int[10];
try
{
for (int i = 0; i < 10; ++i)
{
ordering[i] = -1;
}

for (int i = 0; i < 10; ++i)
{
int count = 0;
while (count < 25)
{
int j = r.Next(10);
bool duplicate = false;
for (int k = 0; k < ordering.Length ; k++)
{
if (ordering[k] == j)
{
duplicate = true;
break;
}
}
if (!duplicate)
{
ordering[i] = j;
break;
}
}
if (ordering[i] < 0)
{
throw new Exception("erro r in setting up test");
}
}

threads[ordering[0]] = startSessionThr ead;
threads[ordering[1]] = endSessionThrea d;
threads[ordering[2]] = endSessionThrea d2;
threads[ordering[3]] = startSessionThr ead2;
threads[ordering[4]] = endSessionThrea d3;
threads[ordering[5]] = startSessionThr ead3;
threads[ordering[6]] = endSessionThrea d4;
threads[ordering[7]] = startSessionThr ead4;
threads[ordering[8]] = endSessionThrea d5;
threads[ordering[9]] = startSessionThr ead5;

for (int i = 0; i < 10; ++i)
{
threads[i].Start();
}
}
catch (Exception e)
{
keepTesting = false;
Console.WriteLi ne(e.Message);
}
finally
{
startSessionThr ead.Join();
endSessionThrea d.Join();
startSessionThr ead2.Join();
endSessionThrea d2.Join();
startSessionThr ead3.Join();
endSessionThrea d3.Join();
startSessionThr ead4.Join();
endSessionThrea d4.Join();
startSessionThr ead5.Join();
endSessionThrea d5.Join();
Console.WriteLi ne();
Console.WriteLi ne(" --------------- repeating test ---------------");
}
}

Console.Write(" Main is finished. (Max time = " +
maxTime.TotalMi lliseconds + " from " + maxMethodName + ")");
Console.Read();
}
#region ThreadStart Delegates
public void Start()
{
StartSession("B etty", 41);
}
public void Start2()
{
StartSession("B oop", 41);
}
public void Start3()
{
StartSession("S punky", 41);
}
public void Start4()
{
StartSession("G rampy", 41);
}
public void Start5()
{
StartSession("F reddy", 41);
}

public void End()
{
EndSession("Bet ty", 41);
}
public void End2()
{
EndSession("Boo p", 41);
}
public void End3()
{
EndSession("Spu nky", 41);
}
public void End4()
{
EndSession("Gra mpy", 41);
}
public void End5()
{
EndSession("Fre ddy", 41);
}
#endregion
}//class SessionStarter

}//namespace
Nov 16 '05 #1
7 1868
I have tested this code further and I do not believe it has any thread
concurrency errors. I hope I'm right. However, I would be willing to pay a
fee to the first person who can point out a valid thread concurrency error
in the code. In other words, if it can suffer from a race condition or
deadlock, just point out the problem and I'll pay you a cash reward
according to the guidelines below.

I'm hope I'm not going to violate any etiquette or other rules by making
this offer. If I am, please let me know. On the other hand, this could be
really fun (and profitable)!

I will pay US$75 via PayPal to the first person who makes a post with a
threading error (as defined above)pointed out in the code. If PayPal isn't
acceptable to the winner, I'll pay via another means (credit card or mailing
a bank check).

This offer is valid for 48 hours from the time of this post.

It is not necessary to specify how to fix the problem -- just identify the
problem and explain why it is a thread concurrency problem.

If the first answer doesn't fully explain the problem, the reward will be
granted to the first subsequent post that does fully explain the problem.
The subsequent post could be from the same person -- in other words, more
than 1 attempt is allowed.

If it isn't really clear that an answer is correct, or there is some other
debate, I suggest that the experts on the newsgroup could act as judges to
decide which answer wins the cash reward. That could also be a fun process,
if it is needed.

If this offer violates any applicable laws in any region it shall not be
valid in that region. If anyone know of a reason that an offer like this
should not be made, please let me know. Otherwise, I"m offering this reward
in good faith and I will pay up to the first person who provides the answer.

Finally, if anyone thinks I should take this question to ExpertsExchange or
Google Answers or some place other than this newsgroup, let me know.
However, there isn't any reason we could establish newsgroups dedicated to
questions with rewards offered. The newsgroups could define the rules up
front and maybe be monitored...
Nov 16 '05 #2
Mr. Mountain <mt*****@mediao ne.net> wrote:
In the following code I simulate work being done on different threads by
sleeping a couple methods for about 40 ms. However, some of these methods
that should finish in about 40 -80 ms take as long as 2300 ms to complete.
This is fairly rare, but the test code below will definitely show it.

Somehow, I must not have my design right.


A couple of things you have wrong:

1) Your access to keepTesting isn't thread-safe. See
http://www.pobox.com/~skeet/csharp/t...latility.shtml

2) I can see where you're testing for the session already being used,
but I can't see where you're then waiting to actually do the work later
on. As far as I can see you're just noticing that it was already being
processed, but then doing the other method anyway.

What error are you actually seeing? What should we be looking out for?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi Jon,

Thanks for your reply. It would not really surprise me if you find problems
with my code, but I haven't actually found anything specific. In fact, the
code works well in a lot of different tests. My main concern is the
excessively long times reported to complete a method that should finish in
about 41 ms. I don't see how/why StartSession, for example, could take 2300
ms on rare occasions.

In regard to your comments about keepTesting, I don't really care about
Main() or keepTesting, or similar fields.
keepTesting is only set to false to end the test and I don't really care if
it this field is thread safe because it isn't part of the code that will
eventually move into production. I know this field is a crappy hack, but I'm
working under a tight time deadline and I am trying to just focus on the
parts of this test code that will be moved into production.

The only important methods are these:
CheckForConflic tingSession
StartSession
HelpStartSessio n
EndSession
HelpEndSession
....and please ignore, as much as possible, any fields or methods used within
these for displaying test results or running the test loop.

I performed another test yesterday. This code shows what I did. (And I have
started using log4net now instead of Console.Write in order to more closely
examine all the output.) If anyone wants the complete code now that I have
made some changes, please let me know. I have not changed any of the core
logic in the above mentioned methods. I just changed the logging and added
another test as described below. The new code requires log4net to be run.

In order to prove that the code does indeed provide the thread
synchronization required, I added a hashtable called checkList. It contains
a check value (int) for each sessionID. Each time a particular sessionID is
being processed, the integer value (named check) which is stored in the
hashtable under the sessionID key, is incremented. When that session ID is
finished being processed, the value in the hashtable is decremented.

The code has to be designed so that a sessionID is only being processed by
one of the two methods at any point in time (and once a method starts
processing, it must finish before the other method can process that
sessionID). The hashtable (checkList) will catch a situation where a
sessionID starts being processed by more than one method.

In the test code, I increment and decrement the check value inside
HelpStartSessio n, in a synchronized block (after Monitor.TryEnte r
successfully returns). Everything works correctly and no sessionID is ever
processed by more than 1 method at a time. This test gives me a lot of
confidence that the code works correctly. (I ran the test for 2 hours with 5
simultaneous application instances open -- so that's 10 hours of testing
with no serious errors. However, I continue to see the long completion times
reported by StartSession and EndSession.)

To finish the test, I temporarily moved the code to increment 'check' out of
the synchronized block in HelpStartSessio n and up to StartSession. As
expected, check then sometimes gets values of 0 or 2, whereas in the correct
code (check incremented within the 'locked' block) check always has a value
of 1. The temporary code is shown below as commented-out code in
StartSession.

public static void StartSession(st ring sessionID, int workAmount)
{
DateTime start = DateTime.Now;
logger.Info(Thr ead.CurrentThre ad.Name + ": " + "entering StartSession
method: " + sessionID);

//NOTE: if this code is uncommented, it shows that the synchronization is in
fact working
//int check = (int)checkList[sessionID];
//checkList[sessionID] = check + 1;
//logger.Info(Thr ead.CurrentThre ad.Name + " processing count = " + (check +
1).ToString());

ActiveSession mySession;
CheckForConflic tingSession(ses sionID, out mySession);
HelpStartSessio n(sessionID, mySession, workAmount);
TimeSpan ts = DateTime.Now - start;
if (ts > maxTime){ maxTime = ts; maxMethodName = "StartSession"; }
logger.Info(Thr ead.CurrentThre ad.Name + ": StartSession time: " +
ts.TotalMillise conds);
}//StartSession

private static void HelpStartSessio n(string sessionID, ActiveSession
mySession, int workAmount)
{
bool entered2 = Monitor.TryEnte r(mySession, waitTime);
if (entered2)
{
logger.Info(Thr ead.CurrentThre ad.Name + ": " + sessionID + " is OK to be
initialized.");

try
{
int check = (int)checkList[sessionID];
checkList[sessionID] = check + 1;
logger.Info(Thr ead.CurrentThre ad.Name + " processing count = " + (check +
1).ToString());

//do all work
Thread.Sleep(wo rkAmount/3);
logger.Info(Thr ead.CurrentThre ad.Name + ": Starting session " + sessionID
+ " initialization. ..");
Thread.Sleep(wo rkAmount/3);
logger.Debug("" );
Thread.Sleep(wo rkAmount/3);
logger.Info(Thr ead.CurrentThre ad.Name + ": " + "Finished session " +
sessionID + " initialization. ");
}
catch (Exception )
{
keepTesting = false;
Exception me = new Exception("Exce ption: Unable to complete session " +
sessionID + " initialization. ");
logger.Error(me );
throw me;
}
finally
{
if ((int)checkList[sessionID] != 1)
{
logger.Error("E RROR: count = " + (int)checkList[sessionID]);
}
checkList[sessionID] = (int)checkList[sessionID] - 1;

sessionsBeingPr ocessed.Remove( sessionID);
Monitor.Exit(my Session);
logger.Info(Thr ead.CurrentThre ad.Name + ": " + sessionID + " is unlocked
by StartSession");
}
}
else
{
keepTesting = false;
Exception me2 = new Exception("Time d out. Could not get Monitor to start
sessionID " + sessionID);
logger.Error(me 2);
throw me2;
}

}//HelpStartSessio n

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mr. Mountain <mt*****@mediao ne.net> wrote:
In the following code I simulate work being done on different threads by
sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long as 2300 ms to complet e. This is fairly rare, but the test code below will definitely show it.

Somehow, I must not have my design right.


A couple of things you have wrong:

1) Your access to keepTesting isn't thread-safe. See
http://www.pobox.com/~skeet/csharp/t...latility.shtml

2) I can see where you're testing for the session already being used,
but I can't see where you're then waiting to actually do the work later
on. As far as I can see you're just noticing that it was already being
processed, but then doing the other method anyway.

What error are you actually seeing? What should we be looking out for?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
If anyone wants to earn 500 points on Experts Exchange, I posted the
question there also.
Nov 16 '05 #5
Mr. Mountain <mt*****@mediao ne.net> wrote:
Thanks for your reply. It would not really surprise me if you find problems
with my code, but I haven't actually found anything specific. In fact, the
code works well in a lot of different tests. My main concern is the
excessively long times reported to complete a method that should finish in
about 41 ms. I don't see how/why StartSession, for example, could take 2300
ms on rare occasions.
I can see why it would if an exception were thrown, and you were
running under the debugger. I can't say I've seen it though.
In regard to your comments about keepTesting, I don't really care about
Main() or keepTesting, or similar fields.
keepTesting is only set to false to end the test and I don't really care if
it this field is thread safe because it isn't part of the code that will
eventually move into production. I know this field is a crappy hack, but I'm
working under a tight time deadline and I am trying to just focus on the
parts of this test code that will be moved into production.


Okay.

I still don't understand what your code was doing though - as I said
before, you seem (in the previous code - I haven't looked at the new
code yet) to check whether or not another thread is processing a
session, but if it is you still do the processing anyway. Isn't that
against the whole point?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Hi Jon,
I appreciate your feedback. See my comments inline.
Mountain

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mr. Mountain <mt*****@mediao ne.net> wrote:
Thanks for your reply. It would not really surprise me if you find problems with my code, but I haven't actually found anything specific. In fact, the code works well in a lot of different tests. My main concern is the
excessively long times reported to complete a method that should finish in about 41 ms. I don't see how/why StartSession, for example, could take 2300 ms on rare occasions.
I can see why it would if an exception were thrown, and you were
running under the debugger. I can't say I've seen it though.
In regard to your comments about keepTesting, I don't really care about
Main() or keepTesting, or similar fields.
keepTesting is only set to false to end the test and I don't really care if it this field is thread safe because it isn't part of the code that will
eventually move into production. I know this field is a crappy hack, but I'm working under a tight time deadline and I am trying to just focus on the
parts of this test code that will be moved into production.


Okay.

I still don't understand what your code was doing though - as I said
before, you seem (in the previous code - I haven't looked at the new
code yet) to check whether or not another thread is processing a
session, but if it is you still do the processing anyway. Isn't that
against the whole point?


The new code is exactly the same except for the addition of a new check to
validate that it is doing what it is supposed to do.

The code does indeed prevent more than one thread from processing a session
at the same time. However, I think the problem, from your perspective, is
that I named my methods inappropriately . The method name
"CheckForConfli ctingSession" seems a bit misleading as I am considering your
comments. This method does indeed let processing continue even if there is a
potentially conflicting session. However, it sets the stage for the
StartSession and EndSession methods to correctly deal with a situation where
a conflict could exist. So it might be better to say that this method is
doing some checking, but not actually handling the conflicts. It also
briefly locks on the whole hashtable (sesssionsBeing Processed). The Start-
and EndSession methods do not lock this collection. They only lock a single
object that is extracted from the collection. This allows a very fine
grained degree of control, which I think is what you have recommended in
your various articles.

I appreciate your input.

I did post this on Google Answers. I offered $50 just for an indepth code
review, regardless of whether any specific threading problems are pointed
out, or not. So if you feel like going thru the code in greater detail,
maybe you can do it thru Google Answers.

Thanks
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7
If you have the ability to answer questions thru Google Answers, please go
there to get $50 for answering my question about this code. The question
there is based on this same code, but it is different in the sense that it
does not require anyone to find/prove that the code has a threading problem.
Just do a review of my code to answer the post on Google Answers. Thanks.

The $75 offer here is about to expire later today. So if you do find a
threading problem in the code and you also provide a reply thru Google
Answers, I guess I'll be paying you $125. But the $75 offer expires soon.
(The $50 from Google answers won't expire so soon.)

"Mr. Mountain" <mt*****@mediao ne.net> wrote in message
news:Fn6wd.2670 32$R05.7603@att bi_s53...
I have tested this code further and I do not believe it has any thread
concurrency errors. I hope I'm right. However, I would be willing to pay a
fee to the first person who can point out a valid thread concurrency error
in the code. In other words, if it can suffer from a race condition or
deadlock, just point out the problem and I'll pay you a cash reward
according to the guidelines below.

I'm hope I'm not going to violate any etiquette or other rules by making
this offer. If I am, please let me know. On the other hand, this could be
really fun (and profitable)!

I will pay US$75 via PayPal to the first person who makes a post with a
threading error (as defined above)pointed out in the code. If PayPal isn't
acceptable to the winner, I'll pay via another means (credit card or mailing a bank check).

This offer is valid for 48 hours from the time of this post.

It is not necessary to specify how to fix the problem -- just identify the
problem and explain why it is a thread concurrency problem.

If the first answer doesn't fully explain the problem, the reward will be
granted to the first subsequent post that does fully explain the problem.
The subsequent post could be from the same person -- in other words, more than 1 attempt is allowed.

If it isn't really clear that an answer is correct, or there is some other
debate, I suggest that the experts on the newsgroup could act as judges to
decide which answer wins the cash reward. That could also be a fun process, if it is needed.

If this offer violates any applicable laws in any region it shall not be
valid in that region. If anyone know of a reason that an offer like this
should not be made, please let me know. Otherwise, I"m offering this reward in good faith and I will pay up to the first person who provides the answer.
Finally, if anyone thinks I should take this question to ExpertsExchange or Google Answers or some place other than this newsgroup, let me know.
However, there isn't any reason we could establish newsgroups dedicated to
questions with rewards offered. The newsgroups could define the rules up
front and maybe be monitored...

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
537
by: Bart Nessux | last post by:
Could someone explain the concept of threads and how I might use them in Python? I was a math major, not a CS major (theory instead of practice). Most of my programming knowledge has grown out of system administration and shell scripting, not professional software development. How could I make this script threaded, and why should I, how would it benefit me? The script already takes up 100% CPU resources, what would using threads gain for...
6
2934
by: Zunbeltz Izaola | last post by:
Hi, I have the following problem. I'm developing a GUI program (wxPython). This program has to comunicate (TCP) whit other program that controls a laboratory machine to do a measurement. I have a dialog box, wiht two buttoms "Start measurement" and "Stop". "Start" executes a function that do the measurement in the following way.
29
3229
by: Jeffrey Maitland | last post by:
Hello all, I am in the process of writing a multithreading program and what I was wondering is a sleep command in an executing function will affect the threads below it? Here is a basic example of what I mean. def main(): temp_var = True while temp_var == True: if
23
6541
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the queue, grab it and run a system command. Now I want to make sure that system command doesn't hang forever, so I need some way to kill the command and have the worker thread go back to work waiting for another queue entry.
11
1674
by: catsup | last post by:
Hi, I have an app written under version Python 2.3.5. The problem I'm having is that it hangs on one of its threads. The thread that hangs does updates to a standard dictionary shared with another thread that only reads this dictionary. This app works beautifully on a single processor boxes in my testing environment, but this problem quickly occurs when the software runs on a dual cpu SMP blade server with hyperthreading turned off,...
8
2403
by: pavvka | last post by:
I'm making multithread server on Linux. Everything works fine, but server reaches threads limint and cannot create any one more. I've wrote simple test code to test this problem. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <pthread.h> using namespace std;
2
9577
by: Kevin Walzer | last post by:
I'm trying to decide whether I need threads in my Tkinter application or not. My app is a front end to a command-line tool; it feeds commands to the command-line program, then reads its output and displays it in a Tkinter text widget. Some of the commands are long-running and/or return thousands of lines of output. I initially thought I needed to use threading, because the GUI would block when reading the output, even when I configured...
12
2323
by: Dave | last post by:
Hi all, I have an application which has some worker threads which often have to stop and wait for some further information from other threads. These pauses will often take a long time (a couple of minutes) and I want the thread to be able to begin work ASAP once the new information arrives so Thread.Sleep isn't the best solution. In .NET 1.1 I used .Suspend and .Resume to handle these pauses but in .NET 2.0 these methods are no longer...
23
4282
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Recently I had a new coworker. There is some dispute between us. The last company he worked for has a special networking programming model. They split the business logic into different modules, and have a dedicated thread for the each module. Modules exchanged info through a in-memory message queue. In my opinion, such a model means very complicated asynchronous
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.