Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CreateThread with more than one parameter

CreateThread with more than one parameter

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fareed Rizkalla
    wrote on last edited by
    #1

    Im trying to pass more than one parameter which I transformed to a thread.

    CPalliniC 1 Reply Last reply
    0
    • F Fareed Rizkalla

      Im trying to pass more than one parameter which I transformed to a thread.

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      Since the thread function accepts a void * as argument (or type compatible with), you may pass a pointer to a whole struct of parameters. Moreover, the thread functiom may access global variables (however, you shouldn't abuse of). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      E 1 Reply Last reply
      0
      • CPalliniC CPallini

        Since the thread function accepts a void * as argument (or type compatible with), you may pass a pointer to a whole struct of parameters. Moreover, the thread functiom may access global variables (however, you shouldn't abuse of). :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        E Offline
        E Offline
        eusto
        wrote on last edited by
        #3

        Try avoiding using globals at all costs. There are very few situations in which you have to use global variables.

        CPalliniC C 2 Replies Last reply
        0
        • E eusto

          Try avoiding using globals at all costs. There are very few situations in which you have to use global variables.

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #4

          I don't completely agree with you. It may be a quick good rule for the newbie. On the other hand the experienced may choose using globals (for instance in small, self-contained projects) :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          E 1 Reply Last reply
          0
          • E eusto

            Try avoiding using globals at all costs. There are very few situations in which you have to use global variables.

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            Alternatively he can use static members of a class instead of "pure" globals, that "looks a bit more object oriented". :)

            class CGlobals
            {
            public:
            static int gGlobalInt;
            static double gGlobalDouble;
            static short gGlobalWarming;
            };

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Computers don't kill programs, users kill programs < > "It doesn't work, fix it" does not qualify as a bug report. <

            1 Reply Last reply
            0
            • CPalliniC CPallini

              I don't completely agree with you. It may be a quick good rule for the newbie. On the other hand the experienced may choose using globals (for instance in small, self-contained projects) :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              E Offline
              E Offline
              eusto
              wrote on last edited by
              #6

              You're right. I've reread my message and I sounded like such a Troll. There are situations in which using globals is not a bad idea. If you have something like: static const std::string application_name = "MyApplication"; passing it as a parameter is counter productive. So this is a situation in which you SHOULD use globals. However, most times, passing variables as arguments rather than using globals is a better design choice.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups