Click here to Skip to main content
14,773,751 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to ask question about c++ win32 console multitasking.
I am working on making a game of chess, The program is completed, but i need to add animations by two or three tasks at the same time. Just like a constant running time somewhere on screen and the program should also stops for user input.[^]

I want something like this.This is much more easier. But I am unable to add pthread.h in visual studio 2010.
Updated 19-Nov-12 4:34am

Then use worker threads. I suggest you reading J. Newcomer's assay on the topic "Using Worker Threads"[^] even if it is MFC oriented, you might gain some insight (e.g. the "don't touch the UI rule").
saad_lah 19-Nov-12 9:08am
Very thnx for ur reply sir,
I have read the article, but i need some thing which is easy for me(i am beginner with threading).
I will be very grateful to u if u could send me a code of multithreading.
Espen Harlinn 19-Nov-12 9:39am
If this is for UI animation only, you could use a regular timer, here is a small tutorial:
Timers Tutorial[^]

An event will be generated at intervals, lets say 100ms, which I guess will be good enough for your animations.

Best regards
Espen Harlinn
saad_lah 19-Nov-12 9:46am
Thnx sir, this has solved the timer problem.
Could u plz tell me how can i add pthread.h lib to visual studio, because i want to do more than one animation in my game. I googled but i failed to find the correct solution.
Espen Harlinn 19-Nov-12 9:51am
Have a look at :
download code + documentation - there is a wide range of examples available, and the library provides a wide range of "higher" level features that I guess you will find useful.

I've also written a "starter" project that you'll find useful:
Jochen Arndt 19-Nov-12 9:59am
I already posted the answer to your solution, but it has been removed with the solution. The first hit when googling for 'pthread win32' is
saad_lah 19-Nov-12 10:12am
@Jochen Arndt :: I got the link and I am now trying to link it with visual studio
saad_lah 19-Nov-12 10:06am
Umm... Truly said, these are higher level features. I am beginner and studying C++ in University, but i will use ACE and ATL features in future :)
Thnx for ur help sir
JackDingler 19-Nov-12 11:53am
pthreads tend to be more heavily used in Linux where processes are light and threads are heavy.

In windows, it's the opposite. Processes are heavy and threads are light.

Use CreateThread() in windows.
Sergey Alexandrovich Kryukov 28-Nov-12 19:55pm
Not quite agree this time. With timers, a lot of problems and pitfalls. Threading is much better for animation, but it requires getting real time in each frame, to build it correctly. See the point?
Espen Harlinn 29-Nov-12 3:46am
Given that there was a need to ask the question, I feel it's an appropriate answer as it's pretty easy to implement.
Sergey Alexandrovich Kryukov 29-Nov-12 12:29pm
Well, this ease looks questionable to me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900