Cenron's Profile User Rating: -----

Reputation: 6 Worker
Group:
New Members
Active Posts:
12 (0.02 per day)
Joined:
23-May 12
Profile Views:
1,896
Last Active:
User is offline Jul 17 2014 07:58 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
XBox
Your Car:
Honda
Dream Kudos:
0
Icon   Cenron has not set their status

Posts I've Made

  1. In Topic: OHMIGOD I JUST FIXED A VERY SERIOUS COMPRESSION PROBLEM!

    Posted 17 Jul 2014

    Oh man! this is hilarious. But obviously a troll.
  2. In Topic: Embarrassing hangman code

    Posted 18 Jun 2013

    Oh man the patience required to write something like this. I don't think I could do it with all that repetition.
  3. In Topic: How to trigger Main function through a Thread?

    Posted 29 Jul 2012

    View PostSkydiver, on 06 June 2012 - 01:56 AM, said:

    The typical approach is to use a mutex, event, or semaphore. The thread that is to be "triggered" will wait on the WaitHandle object, and the thread that is doing the work that says it is done will signal the WaitHandle.

    In your case, though, since all you are doing is waiting for the other thread to be done, you could simply use Join(). See the sample code: http://msdn.microsof...y/95hbf2ta#Y500



    Not to knock your approach man but why use a thread to maintain a timer? Seems like a waste of resources. You can make a simple timer using 2 variables.

    // NOT CLI
    
    int main()
    {
      const u_long interval = 10; // 10 seconds for example.
      u_long startTimer = GetTickCount(); // This is in mili secs.
    
      // The thread that checks for the timer.
      while( true )
      {
         // DO whatever you want here and when 10 seconds goes by the loop exists.
         if( (startTimer + (interval * 1000)) >= GetTickCount() )
           break;
      }
    }
    
    
    
  4. In Topic: set variables from inside a thread

    Posted 29 Jul 2012

    View PostJohnBoyMan, on 29 March 2012 - 02:30 AM, said:

    Hello all. I am working with threads at the moment in my program. The thread is simple and looks like this.
    
    void ThreadProc(void){
    
    				 
    };
    
    
    Thread^ oThread = gcnew Thread( gcnew ThreadStart( this,&qualifiedlist::ThreadProc ) );
    oThread->Start();
    
    


    I have another simplar thread like this but its more complex. I try to set variables in it like this, for example.


    int y;
    void ThreadProc(void){
    y=9;
    				 
    };
    
    
    Thread^ oThread = gcnew Thread( gcnew ThreadStart( this,&qualifiedlist::ThreadProc ) );
    oThread->Start();
    cout<<y;
    
    
    


    y will be 0!

    This is veryyy simple stuff, but if i cout<<y; from outside of the ThreadProc it will be 0 always. I have tried a few other things, i dont ever remeber having this problem, i have been coding for 5 years,so am i nuts? Or should i use a delegate or something? thanks



    Use the static keyword to declare the int as a global variable,
     static int y = 0;
    
    


    The other way you can do it is declare it as a pointer.
    so it can survive the scope of the function, I like this method better because then your not polluting the global namespace.

    unsigned int __stdcall ThreadProc( void *param )
    {
      int *y = reinterpret_cast<int *>( param );
      if( y != NULL )
        (*y) = 9;
    }
    
    
    int main()
    {
      int y = 0; // Or int *y = new int;
    
      // Pass the address of the variable as a reference. 
      CreateThread( &ThreadProc, reinterpret_cast<void *>(&y) );
      std::cout << y << std::endl; // Should be 9.
    }
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
28 years old
Birthday:
October 20, 1985
Gender:
Location:
127.0.0.1
Years Programming:
10
Programming Languages:
C/C++, PHP, Python, Java, ASM, MySQL, HTML, CSS, Java Script

Contact Information

E-mail:
Private

Friends

Cenron hasn't added any friends yet.

Comments

Cenron has no profile comments yet. Why not say hello?