• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
pressgreen

Threads and c++?

10 posts in this topic

Can some one just easily explain process or theory behind using threads. I am not quite sure in my many google searches on the subject what the process is exactly. It seems to be a very loaded word that explaines many things. also in some of my searches have led me to believe that it is something that is java specific. is this tru or can it be used with c++. Any light on the subject would be greatly appreciated.
0

Share this post


Link to post
Share on other sites
Both responses where very very helpful. in fact i have experienced this problem with I/O when trying to load geometry. the process of loading geometry hangs up the entire program and the more complex the geometry the longer the wait. So from what i understand threading would allow me to load geometry on the side of my program with out halting the main thread? I am assuming it would still take time but it would not stop one from continuing interaction with the main program being run by the main thread?
1

Share this post


Link to post
Share on other sites
Also, you should know that your compiler does a lot of parallelization and also optimization such as unrolling, fusion/fision etc and can prob do even more depending on code structure and compiler optimization arguemnts. (it's worth looking in to for many reasons)

This means that a) you can achive some form of parallelization without actually coding it and b) your results might not be as good as you expect it to be (since there is already a lot of optimization going on behind the scenes) or even worse then what the compiler achives for you.
2

Share this post


Link to post
Share on other sites
Just wanted to thank everyone in this thread for great, well-written explanations. I'm not the OP, but I did wonder about this. I feel I have at least a basic understanding of the conceptual rammifications of multi-threaded programming now.
1

Share this post


Link to post
Share on other sites
[quote name='AlanSmithee' timestamp='1347528853' post='4979640']
This means that a) you can achive some form of parallelization without actually coding it and b) your results might not be as good as you expect it to be (since there is already a lot of optimization going on behind the scenes) or even worse then what the compiler achives for you.
[/quote]

I don't think any compiler would do anything like making your single threaded program multithreaded.
What you think about is probably wide data instructions, like SIMD, that the compiler can insert to process data faster, though still in a single thread.

[quote name='frob' timestamp='1347485493' post='4979466']
If you start a new thread, each thread can run an additional line at the same time. Two threads means twice as many lines. Ten threads mean ten times as many lines.
[/quote]

Not really... you can't run more threads in parallell then you have hardware threads in the CPU. With more os threads, they need to share the cpu threads by classic preemptive multitasking. 2 threads per core on an i7 with hyperthreading enabled. though those threads are not really fully parallel either. And you can benefit from more os threads then hardware threads, since threads needs to stall sometimes waiting for memory and disk. CPU architecture is complicated [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Anyhow, processes and threads are not really part of any programming language, they are part of the OS, and are exposed through various API:s to the programming languages.

In a way, you can see the process as your applications "container" in the OS, while its loaded into RAM, and which keeps record of any memory you have allocated to it, threads started, files opened, etc.
threads are the units of execution in your process, that runs code, and share memory between all other threads in that process.
There is always at least one, the "main thread" (and in c, has the entry point "void main(int argc, char** argv)")

Since threads share memory, any memory accesses they do has to be controlled. This is where thread programming can get messy.
The easiest and (when done right) highest performant solution is to make sure that threads are never accessing the same areas in memory at the same time, by having their own copy of everything they need.
You will always need some synchronisation points, but the less you have, the less risk you have for deadlocks and threads just sleeping waiting for other threads to complete.
Synchronisation is done through special objects called "locks", "mutexes", "semaphores", and probably more names I don't recall now. They all work more or less the same though.

Some programming languages have advanced built in features to make it easier to program multithreaded, and structure your multithreaded program, but it all boils down to semaphores, copying data around, and launching thread entry point functions, in the end. Edited by Olof Hedman
1

Share this post


Link to post
Share on other sites
Many C++ compilers have OpenMP built in which makes it much easier to program multithreaded software.

It kinda works as a compiler extension that uses preprocessor statements to tell the compiler what code should be run in parallel (Quite similar to Codeplay's Offload SPU compiler extension.)

For cross platform solutions that I want to be really portable across compilers, I use pthread (POSIX) threads and for Windows I use pthreads-win32 (which I assume just acts as a Win32 thread wrapper internally).
The only annoying one is Solaris, which uses different datatypes (so I just make extensive use of the C or C++ preprocessor to get round this). Edited by Karsten_
1

Share this post


Link to post
Share on other sites
There's a good book describing the multithreading facilities introduced in C++11, "C++ Concurrency in Action: Practical Multithreading" by Anthony Williams.
I'd suggest reading the first two chapters (should answer all your questions and more) available for free here: http://www.manning.com/williams/

Direct links (PDFs):
Sample chapter 1: http://www.manning.com/williams/sample_ch01_CCiA.pdf
Sample chapter 2: http://www.manning.com/williams/sample_ch02_CCiA.pdf
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0