Click here to Skip to main content
12,549,720 members (51,128 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
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.
Posted 19-Nov-12 2:18am
Updated 19-Nov-12 3:34am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100