Thread

Home * Programming * Thread

A Thread is the smallest unit of processing that can be scheduled by an operating system. One or multiple threads can exist within the same process to share its resources such as memory. Modern operating systems support both time-sliced and multiprocessor threading within a process scheduler. Some operating systems such as Windows distinguish worker threads from GUI-threads, which incorporate a message loop, able to receive messages from worker threads. Threads share global data of the process, but use disjoint stacks for local variables.

Chess programs using threads for a parallel search have to deal with synchronization issues, if multiple threads read and write none atomic global data simultaneously, requiring multiple read and/or write cycles. A good step to make a program thread safe, is to avoid global variables and to keep board and game states as locals on the stack. To minimize context switching, chess programs often implement a thread pooling pattern along with explicitly or implicitly controlling processor affinity, where the number of threads of the chess program is less or equal to the number of physical processor cores. Threads are further versatile to control standard input inside an engine.

=See also=
 * Cilk
 * Lazy SMP
 * NUMA
 * Parallel Search
 * Process
 * Shared Hash Table
 * SMP

=Publications=

1994 ...

 * Michael Halbherr, Yuli Zhou, Chris Joerg (1994). MIMD-Style Parallel Programming with Continuation-Passing Threads. Proceedings of the 2nd International Workshop on Massive Parallelism: Hardware, Software, and Applications
 * Robert Blumofe (1995). Executing Multithreaded Programs Efficiently. Ph.D. thesis, MIT, pdf
 * Robert Blumofe, Chris Joerg, Bradley Kuszmaul, Charles Leiserson, Keith H. Randall, Yuli Zhou (1995). Cilk: An Efficient Multithreaded Runtime System. Proceedings of the Fifth ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP), pdf » Cilk
 * Yaoqing Gao, Tony Marsland (1996). Multithreaded Pruned Tree Search in Distributed Systems. Journal of Computing and Information, 2(1), 482-492, pdf
 * Charles Leiserson, Harald Prokop (1998). A Minicourse on Multithreaded Programming. pdf

2000 ...

 * Martin Harvey (2000). Multithreading - The Delphi Way. » Delphi
 * Yue Yang, Ganesh Gopalakrishnan, Gary Lindstrom (2002). Specifying Java Thread Semantics Using a Uniform Memory Model. Java Grande 2002, pdf
 * Hans J. Boehm (2004). Threads Cannot be Implemented as a Library. HP Labs Palo Alto, pdf
 * Jeff Rollason, Dan Orme (2005). Writing cpu intensive AI without multi-threading. AI Factory, Spring 2005
 * Edward A. Lee (2006). The Problem with Threads. Technical Report No. UCB/EECS-2006-1, University of California, Berkeley, pdf

2010 ...

 * Subhash Saini, Haoqiang Jin, Robert Hood, David Barker, Piyush Mehrotra, Rupak Biswas (2011). The Impact of Hyper-Threading on Processor Resource Utilization in Production Applications. NASA Advanced Supercomputing Division, pdf, pdf
 * Anthony Williams (2012). C++ Concurrency in Action: Practical Multithreading.
 * Georg Hager, Jan Treibig, Gerhard Wellein (2013). The Practitioner's Cookbook for Good Parallel Performance on Multi- and Many-Core Systems. RRZE, SC13, slides as pdf

=Forum Posts=

1999

 * Threads by James Robertson, CCC, April 06, 1999
 * gcc / cygwin threads revisited by James Swafford, CCC, July 24, 1999

2000 ...

 * Re: Stormx is this a Crafty Clone?? by Sean Empey, CCC, May 25, 2004 » Windows
 * Approaches to threading by Eric Oldre, CCC, June 15, 2004
 * Kiwi for Win98 and input-reading stuff by Alessandro Scotti, CCC, September 29, 2004 » Kiwi, Windows, C++

2005 ...

 * POSIX threads by Steven Edwards, CCC, July 05, 2005
 * Threading issue under Polyglot by Nathan Thom, Winboard Forum, September 18, 2006 » PolyGlot
 * pthread weirdness by James Swafford, CCC, May 29, 2007
 * multithreading questions by Martin Fierz, CCC, August 08, 2007
 * Threads and cores questions by Casey, CCC, September 07, 2007
 * threads vs processes by Robert Hyatt, CCC, July 16, 2008
 * threads vs processes again by Robert Hyatt, CCC, August 05, 2008
 * Hyperthreading Hype predates Intel by Steven Edwards, CCC, February 07, 2009
 * Multithreaded movepath enumeration (perft) by Steven Edwards, CCC, February 27, 2009
 * kbhit taking huge CPU?? by John Merlino, CCC, April 01, 2009 » C

2010 ...
2011 2012 2013 2014
 * Stockfish-1.7.0 Hyper-threading Detection by Louis Zulli, CCC, April 09, 2010
 * To hyperthread or not to hyperthread (Crafty tested) by Martin Thoresen, CCC, October 24, 2010 » Crafty
 * Hyperthreading by Gerd Isenberg, CCC, September 17, 2010
 * Thread management / organization in parallel processing? by Nguyen Pham, CCC, December 06, 2010
 * Have Crafty's threads never gone to sleep? by Nguyen Pham, CCC, January 31, 2011
 * On parallelization by Onno Garms, CCC, March 13, 2011
 * hyper threading and move generation by Gabor Buella, CCC, August 01, 2012 » Move Generation
 * Multi-threaded memory access by ThinkingALot, OpenChess Forum, February 10, 2013 » Memory, Shared Hash Table
 * Hyperthreading and Computer Chess: Intel i5-3210M by Mike Scheidl, CCC, April 12, 2013
 * Implementation of multithreaded search in Jazz by Evert Glebbeek, CCC, April 20, 2013 » Parallel Search, Jazz
 * use sleeping threads by Don Dailey, CCC, July 10, 2013 » Stockfish
 * C++ Question by Ted Wong, CCC, July 30, 2013 » C++
 * Writing to a Text File (Thread Safe) by Steve Maughan, CCC, August 10, 2013 » Logging
 * SMP and Thread Pool Design pattern by Edsel Apostol, CCC, October 02, 2013
 * Multithreaded LRU by Alvaro Cardoso, CCC, October 06, 2013 » Memory, Endgame Tablebases
 * C++11 threads seem to get shafted for cycles by User923005, OpenChess Forum, March 18, 2014 » C++, Parallel Search, Senpai
 * Threads-Test by Andreas Strangmüller, CCC, March 18, 2014 » Parallel Search, Stockfish
 * Threads-Test - SF, Zappa, Komodo - 1 vs. 2, 4, 8, 16 Threads by Andreas Strangmüller, CCC, May 04, 2014 » Stockfish, Zappa, Komodo
 * Threads factor: Komodo, Houdini, Stockfish and Zappa by Andreas Strangmüller, CCC, May 17, 2014 » Komodo, Houdini, Stockfish, Zappa
 * TinyThread++ by Alberto Sanjuan, CCC, July 24, 2014
 * Best way to handle input thread by Stefano Gemma, CCC, August 09, 2014
 * (Why) Is hyperthreading bad for chess engines? by Syed Fahad, CCC, September 23, 2014
 * Threads test incl. Stockfish 5 and Komodo 8 by Andreas Strangmüller, CCC, October 09, 2014
 * Threads test - Stockfish 5 against Komodo 8 by Andreas Strangmüller, CCC, October 10, 2014 » Thread, Parallel Search, Stockfish, Komodo
 * Threads test incl. Crafty 24.1 by Andreas Strangmüller, CCC, October 15, 2014 » Crafty
 * Current data - threads-nps efficiency up to 32 threads by Andreas Strangmüller, CCC, October 24, 2014

2015 ...

 * Stockfish with 16 threads - big news? by Louis Zulli, CCC, February 15, 2015
 * Explanation for non-expert? by Louis Zulli, CCC, February 16, 2015 » Stockfish

2016
 * Thread count limits and core counts by Steven Edwards, CCC, March 22, 2015
 * Thread synchronization questions for experts by Steven Edwards, CCC, April 21, 2015 » Symbolic
 * A cautionary tale on thread safety by Steven Edwards, CCC, April 25, 2015
 * A Nice routine by Steven Edwards, CCC, May 12, 2015
 * Deep split perft by Steven Edwards, CCC, May 29, 2015 » Perft, Symbolic
 * thread affinity by Martin Sedlak, CCC, July 03, 2015
 * Stockfish now benefits from hyperthreading by Dmitri Gusev, CCC, November 12, 2015 » Stockfish
 * Using more than 1 thread in C beginner question by Uri Blass, CCC, January 11, 2016
 * Threads test incl. Stockfish 7 by Andreas Strangmüller, CCC, January 11, 2016 » Parallel Search, Stockfish
 * Threads test incl. Komodo 9.3 by Andreas Strangmüller, CCC, January 17, 2016 » Komodo
 * threading by Folkert van Heusden, CCC, March 03, 2016
 * lazy smp using ms vs2015 c++11 std::async by Edward Yu, CCC, July 29, 2016 » Lazy SMP
 * Baffling multithreading scaling behavior by Tom Kerrigan, CCC, September 06, 2016
 * Re: Baffling multithreading scaling behavior by Robert Hyatt, CCC, September 07, 2016


 * Some hyperthreading results by Kai Laskos, CCC, September 12, 2016
 * Stockfish 8 - Double time control vs. 2 threads by Andreas Strangmüller, CCC, November 15, 2016 » Doubling TC, Diminishing Returns, Playing Strength, Stockfish
 * Hyperthreading debate reopened? by Zat, Rybka Forum, December 03, 2016
 * Diminishing returns and hyperthreading by Kai Laskos, CCC, December 27, 2016 » Diminishing Returns, Match Statistics, Playing Strength
 * Core behaviour by Ed Schroder, CCC, June 28, 2017 » Engine Testing
 * Lazy SMP >4 Thread Slowdown by Can Cetin, CCC, November 29, 2017 » Lazy SMP
 * Re: Lazy SMP >4 Thread Slowdown by Ronald de Man, CCC, November 29, 2017


 * More questions about threads by Patrice Duhamel, CCC, April 21, 2018 » Young Brothers Wait Concept

=External Links=

Thread

 * Thread (computing) from Wikipedia
 * Thread safety from Wikipedia
 * Thread pool pattern from Wikipedia
 * Thread-local storage from Wikipedia
 * Light-weight process from Wikipedia
 * Fiber (computer science) from Wikipedia
 * Green threads from Wikipedia
 * Coroutines from Wikipedia
 * Open Directory - Computers: Programming: Threads
 * Thread (disambiguation page) from Wikipedia

Multithreading

 * Multithreading from Wikipedia
 * Simultaneous multithreading from Wikipedia
 * Temporal multithreading from Wikipedia
 * Processor affinity from Wikipedia
 * Super-threading from Wikipedia
 * Hyper-threading from Wikipedia

Posix

 * Native POSIX Thread Library from Wikipedia
 * GNU Portable Threads
 * LinuxThreads from Wikipedia
 * FSU Pthread from Wikipedia
 * POSIX threads explained by Daniel Robbins, IBM developerWorks
 * POSIX Threads (pthreads) for Win32 (win64 )

Windows

 * Using Processes and Threads, Windows Desktop Development
 * Creating Threads


 * Processes and Threads, MSDN
 * _beginthread, _beginthreadex, MSDN
 * Thread Class (System.Threading) .NET. MSDN
 * Win32 Thread Information Block from Wikipedia
 * Windows API Tutorial: Using Threads, Reliable Software
 * Processes, Threads, and Jobs (pdf) from Microsoft® Windows® Internals, Fourth Edition: Windows 2000, Windows XP, and Windows Server 2003 by David Solomon and Mark Russinovich

C++

 * Brief Review to C++ / Process / Thread (pdf)
 * JThreads/C++ - “Java-like Threads for C++” (pdf)
 * Chapter 24. Thread - Boost 1.47.0 by Anthony Williams
 * Qt 4.7: Thread Support in Qt
 * Input thread, code from Alaric Downloads by Peter Fendrich
 * TinyThread++ - Portable thread library for C++

Java

 * Thread (Java 2 Platform SE 5.0)
 * Processes and Threads (The Java™ Tutorials > Essential Classes > Concurrency)

GPU

 * Parallel Thread Execution from Wikipedia » SIMD and SWAR Techniques

=References=

Up one Level