|
Thanks!
These articles seem to be a bit biased to Win32 - we actually write cross-platform code, and the Win32 specifics tend to be embedded deep within our libraries. However, I'm planning to do a personal project on Windows sometime soon, so these should help.
While I'm on, perhaps I should post a few more of the links I've found, although these are more introductory tutorials:
CodeProject[^]
Paul Bridger[^]
www.intelligentedu.com[^]
FlipCode[^]
HotScripts[^]
Advanced topics:
Hyper Threading[^]
Thread Pools[^]
- Steven
|
|
|
|
|
Steven Swart wrote: These articles seem to be a bit biased to Win32
Well, no surprise there.
You're posting on a forum dedicated to windows programming with C++ and the MFC framework in particular.
However, the concurrency problems addressed in the essay applies to all platforms, not only Win32.
Perhaps you should take a look at the POSIX thread library for Win32.
Writing code for multithreading with POSIX thread API makes the code more portable.
Have a look here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Heh. I do realise this forum is biased to Win32, but I've yet to find a better one for my purposes...
A bit of background on our architecture, our apps are all server applications (services or daemons). GUI access is via a web-interface, so I don't need to know any GUI/OS specific stuff to do my job. Our codebase compiles on Windows, Solaris, Linux and FreeBSD. We do use pthreads for our unices, but our Windows build uses the native Win32 API. All of this is however nicely abstracted in our threading classes.
At some stage I would like to start developing my own applications though, and to do that I will need to know the nitty-gritty. So I'm starting to do the research now.
Thanks for all your help!
S.
|
|
|
|
|
> Heh. I do realise this forum is biased to Win32, but I've yet to find a better one for my purposes...
OK, found a discussion on Slashdot which some of you may find interesting:
Good Books On Programming With Threads? [^]
|
|
|
|
|
|
Thanks, will have a look.
|
|
|
|
|
You're welcome.
|
|
|
|
|
Hi All,
I have couple of questions regarding threads.
In My VC application,Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST.?
and Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?.
Thanks in advance.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST
Technically, Yes. In the real world if you do this your customers will not like you. You will hog the entire system, probably even on dual core systems. Don't do this, there is really no need unless you're writing some kind of real time control system and Windows is the wrong place to be doing that or unless you're intending to replace a core windows driver.
sunilkumar.d wrote: Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?.
I can't remember off the top of my head which API call AfxBeginThread ends up using but I'm guessing it's _begin_thread from the CRT. If you mix these threads with threads started with CreateThread then don't use Thread specific Locales or TLS in your CreateThread Thread and avoid passing objects beetween them unless you're in full control of those object, i.e. they're entirely your code and your data, no Window handles, streams or objects with base classes buried in the Windows headers. If you do that you should be fine but I've no idea why you would want to.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
sunilkumar.d wrote: In My VC application,Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST.?
Why don't you try? Be aware about this info [^].
sunilkumar.d wrote: and Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?
Why do you need the above?
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]
|
|
|
|
|
sunilkumar.d wrote: Can I have two worker threads with the
priority set to THREAD_PRIORITY_HIGHEST.?
Yes, you can.
But chances that you are trying to solve a problem the wrong way is very close to 100%. Manipulating thread priorities is almost always wrong and is often used to disguise performance bottleneck that should be solved on the design level.
Explain what you're trying to do and why you think you need to increase the priority level of the threads. Most likely there is a better solution.
sunilkumar.d wrote: Is there any problem , if one thread created with "CreateThread" and
one with "AfxBeginThread"?.
If you're using MFC, and you are because otherwise AfxBeginThread() wouldn't be declared, you have to use AfxBeginThread() due to inner workings of the framework.
Read more about threads here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks for the immediate response.
Actually i have two threads.
One runs script file, which consists of some commands.
Each command to be sent to hardware via serial port and receive the result.
The other thread is serial port read thread.
If the Threadpriority is normal , my script file runs a bit slowly.
Thats why I want to increase the priority.
Regards,
Sunil Kumar
|
|
|
|
|
sunilkumar.d wrote: Actually i have two threads.
One runs script file, which consists of some commands.
Each command to be sent to hardware via serial port and receive the result.
The other thread is serial port read thread.
If the Threadpriority is normal , my script file runs a bit slowly.
Have you considered why the script runs slowly?
What you do by increasing the thread priority is saying "when this thread runs it's more important than other threads and should not be disturbed". My point is that if this is a problem, your thread that executes the script is interrupted by other threads. If that's you problem, have you considered why it is so?
Have you by any chance written a call to ::Sleep() somewhere? If so, that is most likely your source of problem. Read the article I linked to in my previous post followed by this[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thanks a lot Roger
Regards,
Sunil Kumar
|
|
|
|
|
|
Stingray Studio is used to create a SECCustomStatusBar to display a toolbar in my application. The code is written in C++ using MFC, but I want to prevent the user from having the ability to resize the toolbar. The toolbar is to automatically resize when the application is not maximized and the user sets the application's window size to his/her preference.
Can this toolbar remove the ability for the operator to click, hold, and drag the bottom right corner of this toolbar to resize it?
|
|
|
|
|
Handle WM_MINMAXINFO. I think you should give the same number for min and for max, so there is no range for the user to change size.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Ive managed to read a whole text file into a string. The text file has 200 lines. I wanna read a specific line from the string, how can i do it? I tried getline(); but the problem is that it reads a line rite from the starting position of the string but not from a specific point.
nOmI
|
|
|
|
|
Well, you may read a line at time or may move a pointer inside the buffer.
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]
|
|
|
|
|
kindly would u like to elaborate ur reply bcoz im a bit new in C++ programming.
nOmI
|
|
|
|
|
Instead of reading the whole file at once, read it one line at a time until you get to the desired line. Otherwise, you'll need to parse the buffer (a line will by separated by a \r\n pair).
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Thank you for elaborating my lazy answer.
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]
|
|
|
|
|
CPallini wrote: Well, you may read a line at time or may move a pointer inside the buffer.
And you got 1 vote at time but now you get a pointer of 5.
|
|
|
|
|
Thank you, pal.
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]
|
|
|
|
|
Did you try with CFile::Read ?
|
|
|
|