assignment of value by thread problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: assignment of value by thread problem

  1. #1
    Join Date
    Sep 2008
    Posts
    93

    assignment of value by thread problem

    Hi @ all,

    In a thread I´m receiving messages from socket.
    If a specific message is income I´m setting a boolean to true.
    In a method of my main process I have an endless loop which
    has to end if the variable in thread is set to true.

    The problem is it needs about 4 to 5 seconds from setting the value to true and
    that the method will notice it.

    What can I do that the method ends immediatly if the needed message is coming in?

    Best regards
    CrazyPlaya

    P.S.: I forget to say the application is running as a service in Windows.
    Last edited by CrazyPlaya; March 25th, 2010 at 02:49 AM.

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: assignment of value by thread problem

    Hard to say without seeing any code. You're probably not polling the variable often enough, or are blocked by some other operation in your loop.

  3. #3
    Join Date
    Sep 2008
    Posts
    93

    Re: assignment of value by thread problem

    here a snippet of my code

    Code:
    while(running)
    {
          //mutex is just a class which used Critcal Sections.
          mutex->start();
          nRf = recvfrom(mysocket, buffer, ...);
          if(nRf > 0)
          {
                if(strMsg.compare(buffer) == 0)
                {
                      m_bEnding = true;
                } 
          }
          mutex->end();
    
    }
    It seems that the variable is blocked for this time.
    How can I do it out of blocking?

  4. #4
    Join Date
    Sep 2005
    Location
    New Delhi, India
    Posts
    332

    Re: assignment of value by thread problem

    Quote Originally Posted by CrazyPlaya View Post

    It seems that the variable is blocked for this time.
    How can I do it out of blocking?

    Try using select call. select() gives you the power to monitor several sockets at the same time. It'll tell you which ones are ready for reading, which are ready for writing, and which sockets have raised exceptions, if you really want to know that.
    Appreciate others by rating good posts

    "Only buy something that you'd be perfectly happy to hold if the market shut down for 10 years." - Warren Buffett

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center