Results 1 to 5 of 5

Thread: monitor util thread block at windows system

  1. #1
    Jacky_Lee is offline Registered User
    Name: jacky lee
    Organization: ustb
    Project: graduate student recearch
    Join Date
    Jul 2006
    Posts
    13

    Question monitor util thread block at windows system

    hi
    i have a problem with monitor class at windows. I made a queue with monitor class, use notify() in put and timedwait() in get. when i have several(>20) thread to get and 1 thread to put, the thread will block. i pause the program , found one of the get thread blocked at _gate.wait() of prewait(), and another get thread blocked at _queue.wait() of postwait().

    these is my test code
    Code:
    #include <IceUtil/Thread.h>
    #include <IceUtil/Time.h>
    #include <IceUtil/Monitor.h>
    #include <Ice/Ice.h>
    #include <iostream>
    #include <list>
    
    template<class t> class Queue: public IceUtil::Monitor<IceUtil::Mutex>
    {
    public:
    	Queue(){};
    	void put(const t & item) {
    		IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
    		_q.push_back(item);
    		notify();
    	}
    	bool timedGet( t & ret, const IceUtil::Time& timeout)
    	{
    		IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
    		if (_q.size() == 0)
    			timedWait(timeout);
    		if (_q.size() == 0)
    		{
    			return false;
    		}
    		ret = _q.front();
    		_q.pop_front();
    		return true;
    	}
    private:
    	std::list<t> _q;
    };
    
    Queue<int> m_pQ;
    class testthread : public IceUtil::Thread
    {
    
    public:
    	virtual void run()
    	{
    		int n = 0;
    		srand((int)IceUtil::Time::now().toMicroSeconds());
    		while(true)
    		{
    			int Result;
    			int nTime = rand() % 1000;
    			m_pQ.timedGet(Result, IceUtil::Time::microSeconds(nTime) );
    			Sleep(10);
    			std::cout << nTime << " ";
    		}
    	}
    };
    void main()
    {
    	for (int i = 0; i < 100; i++)
    	{
    		testthread* p = new testthread;
    		p->start();
    	}
    	while(true)
    	{
    		m_pQ.put(2);
    		Sleep(1);
    	}
    	return;
    }
    Jack Lee
    University of science and technology of beijing

  2. #2
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    Thanks for the problem report. We're looking into the problem.

  3. #3
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    BTW, can you fix the name in your profile please? You are required to give your full real name in your profile for free support on these forums.

  4. #4
    Jacky_Lee is offline Registered User
    Name: jacky lee
    Organization: ustb
    Project: graduate student recearch
    Join Date
    Jul 2006
    Posts
    13
    ok, i have changed
    Jack Lee
    University of science and technology of beijing

  5. #5
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    Thanks for the bug report and test case. I've posted a patch that fixes this problem. Please see patch #3 for Ice 3.2: Fix for condition variable implementation under Windows. for details.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Java Performance of Ice.Util.createInputStream
    By glennleidy in forum Help Center
    Replies: 9
    Last Post: 12-19-2009, 08:11 AM
  2. thread pool (block reading?)
    By zouming in forum Help Center
    Replies: 4
    Last Post: 04-01-2008, 11:03 PM
  3. Help! Why ice_response for AMD block?
    By soloman817 in forum Help Center
    Replies: 9
    Last Post: 11-05-2007, 12:03 PM
  4. ICE thread pool model under windows
    By simondu in forum Comments
    Replies: 3
    Last Post: 09-21-2007, 06:08 AM
  5. Windows Installer assumes System Drive is on C:
    By RyanFogarty in forum Comments
    Replies: 5
    Last Post: 02-08-2005, 07:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •