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

Hybrid View

  1. #1
    Join Date
    Aug 2019
    Posts
    72

    need help with threads

    Hi, I am newbie to managed c++.

    I need a code with main function that four threads run four instances of this class , Animal, simultaneously.
    Each instance prints a different animal kind. "cat", "dog", .,.
    where to create thread should be at?

    Code:
    ref class Animal()
    {
    	Animal(String ^s)
    	{
    		Console::Writeline(s)
    	}	
    		
    	// where the create thread should be at?
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: need help with threads

    In the main()
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2019
    Posts
    72

    Re: need help with threads

    Works now.

    if got a Add function in a shared header:

    Code:
    int Add(int a, int b)
    {
        return a+b;
    }
    is it thread safe if multiple threads calling it?. if not how to make it safe to avoid unexpected results?.
    Last edited by @EE@; September 26th, 2021 at 06:06 PM.

  4. #4
    Join Date
    Aug 2019
    Posts
    72

    Re: need help with threads

    No opinion on the last question?!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured