• 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.

Archived

This topic is now archived and is closed to further replies.

Lethe

Multithread Varibles...

7 posts in this topic

I''m running a multi-threaded C++ program and simply want to have a global varible which is different for each thread - ie in thread #1 it could contain 6 whilst in thread #2 it could contain 2. Now under borlands compillers (Or windows - it''s specific to one of them at any rate.) it''s quite easy to do -
int __thread GlobalVar;
 
Unfortunatly the program also has to run on linux - so i''m after a way that will work for both or could easilly be integrated with the windows equivalant via the preproccesor. I would prefer to avoid anything thats slow - so having a hash table by the thread number or somthing similer really would be a last ditch techneque. Anyone got any experiance/ideas? Thanks in advance for any help. -Lethe
0

Share this post


Link to post
Share on other sites
Using C++, aren''t your threads objects of some sort? If so, then these variables should probably be members of your thread objects. As globals should technically be global, and using odd compiler-specific workarounds to make globals less-than-global is generally not a good idea. (Of course, using global variables is usually less than a good idea, but I digress...)
0

Share this post


Link to post
Share on other sites
There is no class ''generally'' associated with each thread - there is some data associated with each thread, which is a class, but it can''t be accessed by methods/functions called by that thread - ie they are in different classes that are in use by multiple threads, and passing that data down as a pointer is stupidly impractical.

-Lethe
0

Share this post


Link to post
Share on other sites
There is a simple solution considering you ARE using C++. Encapsulate your threads in a general class, and when you want to create a thread, simply create an instance of that class. The class could have a member variable (the thread specific global variable) as Kylotan suggested, and you''re on your merry way.
0

Share this post


Link to post
Share on other sites
That is simply not going to work, as I said before. To put the point across, we''re talking about a 25k line server with different classes for different services within that server - each of these classes is initialised once and used seperatly by different threads - each thead being a different user. These classes methods need access to some thread-specific data which can''t be passed down the line via pointers, cos as I said, it''s 25k lines long and I''m not editting that much code!

-Lethe
0

Share this post


Link to post
Share on other sites
Depends. You might wanna try and get your hands on an HP C++ compiler for Linux. __thread was original introduced in HP C therefore I''m pretty sure it is in HP C++ as well

Otherwise, if I am not mistaken, underneath __thread uses a hash table of dynamic structures for each thread, and this is also the method used on alot of procedural Unix servers which do not use HP C.

It is only slow if you expect tens of thounsands of simultaneous connections.

Seeya
Krippy
0

Share this post


Link to post
Share on other sites
Intresting - I''ll look into that, though I would of guessed that it wasn''t a hash table but stored in each thread''s data block - if it turns out to be a hash table I might as well just code it myself though.
Thanks.

-Lethe
0

Share this post


Link to post
Share on other sites
So your thread instances sound like "singleton" (I hate that word, BTW) classes for each service you are running? If this is TCP/IP (or any other handshaking protocol) then you''re going to need a listener thread class and a separate worker thread class, wouldn''t you? This would allow your service listener to be singleton, and manage (fork and kill) each of the other separate processes that are its working connections. This is how we solved a multithreading problem in *nix without having to debug something like pthreads and make it work on more esoteric environments.

the listener receives your request, then takes the socket handle (pid, whatever) and hands it as a paramater to a forked open worker thread. Data is matched up by having a place in the message (or in your internal messaging layer) that holds the pid of the worker process in question. the message is passed from worker to the engine class doing all the db work or whatever, and the engine class knows to which pid it should hand the completed work.

Sounds like fun, huh. Secondarily, if you need globals that work across the board, you may as well keep a memory map or memory-mapped-file that is managed by a Globals class, also singleton, to which you would talk in order to retrieve your global values.

------------
-WarMage
...sorry for the mess, you''ll clean it right up.
0

Share this post


Link to post
Share on other sites