Page 2 of 2

Posted: Fri Jul 24, 2009 3:22 pm
by leiradella
Dark Alchemist wrote:I still would like to be enlightened if you know how I could do multi-threads without it being in a global space on Windows.
It really depends on what you're trying to do. Threads usually work with their own local variables allocated in their own stack or dynamic allocated space from the heap. Assuming you're using CreateThread to, well, create new threads, you can also pass a pointer to whatever you want via the lpParameter parameter of the function (see CreateThread at MSDN.)

If you need global variables to change information between threads, you better use mutexes and/or other synchronization mechanisms specifically designed for this because it's not thread-safe to read from/write to global variables from different threads without a lock to ensure atomic reads and writes.

Cheers,

Andre

Posted: Fri Jul 24, 2009 7:54 pm
by phlox81
Dark Alchemist wrote:
phlox81 wrote:Don't use global variables.
Also static functions are only few times helpful.
Static must be used in windows for doing threads or at least that is everything I have read says.
Sorry but thats just bullshit.
I've done severalt threading applications on Windows, and wxThread does not require anything static.
Nor Boost::thread, nor QThread.

phlox

Posted: Fri Jul 24, 2009 11:55 pm
by leiradella
phlox81 wrote:
Dark Alchemist wrote:
phlox81 wrote:Don't use global variables.
Also static functions are only few times helpful.
Static must be used in windows for doing threads or at least that is everything I have read says.
Sorry but thats just bullshit.
I've done severalt threading applications on Windows, and wxThread does not require anything static.
Nor Boost::thread, nor QThread.

phlox
Yup, it is bull shit. the static keyword changes the scope of the declared function to be local to the object file it's compiled into, i.e. it won't be visible to the linker. Everyone uses it a lot to avoid bloating the global scope with names not meant to be globally visible.

Unless he's talking about static class methods, that for sure need to be static because the hidden this pointer won't be automatically sent to the method when the thread starts and you get a nice crash.

Cheers,

Andre

Posted: Sat Jul 25, 2009 4:19 am
by protocol
It seems like there is a party in this thread. So I will add my two cents.

Have you tried using events to provide data to the threads?

Posted: Sun Jul 26, 2009 8:07 am
by Dark Alchemist
phlox81 wrote:
Dark Alchemist wrote:
phlox81 wrote:Don't use global variables.
Also static functions are only few times helpful.
Static must be used in windows for doing threads or at least that is everything I have read says.
Sorry but thats just bullshit.
I've done severalt threading applications on Windows, and wxThread does not require anything static.
Nor Boost::thread, nor QThread.

phlox
Since we have cursing then how in the EFF do you do windows threading, no not wxthreads, but windows threading otherwise?

Code: Select all

DWORD WINAPI Thread(LPVOID lpParam)
That is what Windows wants for CreateRemoteThread and CreateThread. I have tried shooting it XXX::Thread before but it either never worked or crashed since it doesn't like thread created in the namespace way. http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Posted: Sun Jul 26, 2009 8:10 am
by Dark Alchemist
protocol wrote:It seems like there is a party in this thread. So I will add my two cents.

Have you tried using events to provide data to the threads?
No, I haven't but I never got around my include issue so in this project I am stuck with just including the .cpp and leaving it out of the project window. It works and for now that is all I care about (time issues). Why it wants it like that I don't know why but I got tired of fighting it for 3 or 4 days.