crazy proj : No 4 - multi threading
Baiscs:
1. Thread local
new ThreadLocal<String>(()=>"hehe")
LocalDataStoreSlot slot ; Thread.setData(slot,123)
2. Thread with parameters
class MyThread<T>
T data
3. background thread
IsBackground=false
4. control thread
start sleep join abort
5. ThreadPool
ThreadPool.QueueUserWorkItem(_ => Console.WriteLine(Thread.GetData(slot) == null));
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
knowledge:
1. In .NET 4.5 the maximum is 1,000 threads by default on 32-bit processes, and 32,767 threads in 64-bit mode, although you can change that—the ThreadPool class has a SetMaxThreadsmethod that lets you configure different limits for your process.
2. By default, each thread gets 1 MB of the process’s address space reserved for its stack, so by the time you have 1,000 threads, you’ll be using 1 GB of address space for stacks alone.
3. I/O and worker threads. I/O invoke methods you provided as callbacks
(modify threadpool size should consider this difference )
reference:
http://www.cnblogs.com/lvcy/archive/2012/06/16/2551539.html
http://www.cnblogs.com/mgen/archive/2012/02/24/2366578.html
threadpool
http://www.cnblogs.com/sashow/archive/2007/02/08/644679.html
http://www.cnblogs.com/sashow/archive/2007/02/08/645016.html
浙公网安备 33010602011771号