473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

threading issues

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
1 1127
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Varun | last post by:
Hi Friends, Department of Information Technology, Madras Institute of Technology, Anna University, India is conducting a technical symposium, Samhita. As a part of samhita, an Online Programming...
1
by: Your Friend | last post by:
Hello All, I'm having issues capturing the output from a program while using threading. Program runs ok when I run without threading. Here's my Python code and the Java class that is called by...
21
by: Illumineo | last post by:
My application uses multiple-threads and is a kind of AI simulation or ALife. This works fine but I was wondering if and how one can make use of hyper-threading in C#? Thanks for any hint,...
1
by: James T | last post by:
Hi I am considering spawning a background thread to perform a long running task in my asp.net application and I was hoping someone could shed some light on several issues for which I have not...
16
by: One Handed Man \( OHM - Terry Burns \) | last post by:
Sorry if this gets duplicated, but I posted it and cant see it for a long time so repost. . . I have an application which is writing to a graphics object, the main UI thread and a worker thread...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
3
by: Richard MSL | last post by:
I have a C# application that works, with a main menu where the user can choose different options that run, and then return to the menu. I want to change it so that the user can starting running an...
5
by: George Maicovschi | last post by:
As multi-threading is not built in PHP I've been using a hack letting the Apache server handle the multi-threading issues, but I'm really curious of other approaches to this issue. If anyone has...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.