Click here to Skip to main content
11,715,165 members (73,358 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hey,
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.

http://www.tutorialspoint.com/cplusplus/cpp_multithreading.htm[^]

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
saad_lah1.4K
Edited 19-Nov-12 3:34am
v3
Rate this: bad
good
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").
  Permalink  
Comments
saad_lah at 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 at 19-Nov-12 9:39am
   
5'ed!
Rate this: bad
good
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
  Permalink  
Comments
saad_lah at 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 at 19-Nov-12 9:51am
   
Have a look at :http://www.cs.wustl.edu/~schmidt/ACE.html
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: http://www.codeproject.com/Articles/143484/Integrating-ACE-and-ATL
Jochen Arndt at 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 http://www.sourceware.org/pthreads-win32/.
saad_lah at 19-Nov-12 10:12am
   
@Jochen Arndt :: I got the link and I am now trying to link it with visual studio
saad_lah at 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 at 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 at 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?
--SA
Espen Harlinn at 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 at 29-Nov-12 12:29pm
   
Well, this ease looks questionable to me...
--SA

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
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