CreateThread with more than one parameter
-
Im trying to pass more than one parameter which I transformed to a thread.
-
Im trying to pass more than one parameter which I transformed to a thread.
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] -
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] -
Try avoiding using globals at all costs. There are very few situations in which you have to use global variables.
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] -
Try avoiding using globals at all costs. There are very few situations in which you have to use global variables.
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. <
-
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]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.