By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,204 Members | 1,465 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,204 IT Pros & Developers. It's quick & easy.

threading issues

P: n/a
Hi:

I am new to multithreaded applications, and was having some problems
coordinating a few threads.

Here is the code I use:
ContextStorage cs = new ContextStorage(HttpContext.Current);

cs.setThread(runRetrieval);

runStart = new Thread(new ThreadStart(cs.RunStart));
runStart.Start();
Monitor.Enter(cs);

// wait until first of two threads completes and pulses all
Monitor.Wait(cs);

Monitor.Exit(cs);
// do same for second of the two threads
Monitor.Enter(cs);

Monitor.Wait(cs);

Monitor.Exit(cs);

// now do some other work

Basically I have this main thread, which starts and waits on a thread
runStart, which in turn starts and waits on another thread
runRetrieval. The way I communicate among these is that when the
runRetrieval completes, it pulses all waiting threads, including this
main one. runStart also gets pulsed, does some other work, and then
pulses again, which finally allows this main thread to continue
execution.

For some reason, however, even though it receives the first pulse, the
main thread hangs subsequently. Can anyone help me with this problem?
Thanks

May 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
<ab**********@gmail.com> wrote:

<snip>
For some reason, however, even though it receives the first pulse, the
main thread hangs subsequently. Can anyone help me with this problem?


Is it possible that your two threads are *both* pulsing the monitor
before you get to the second Wait? It sounds like you might want either
a semaphore or a producer/consumer queue.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 14 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.