C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

c++的多线程编程(资料收集)

c++的多线程编程


由于现在的标准c++库中没有对多线程的支持,所以如果我们想使用多线程,就是使用其他的库支持。


1)使用windows提供的多线程支持

  中文msdn中查找多线程编程,可以找到。
  http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vccore/html/_core_multithreading_with_c_and_win32.asp

2)使用MFC提供多线程支持

  中文msdn中查找多线程编程,可以找到。
http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/vccore/html/_core_multithreading_with_c_and_win32.asp

3)使用boost提供的多线程

http://www.boost.org/doc/html/threads.html


4)多核程序设计技术——通过软件多线程提升性能(intel出的书)


5)codeproject上C++下的多线程

6) windows核心编程

7)intel :http://shareit.intel.com/WikiHome/Articles/111111287

8)intel:http://shareit.intel.com/WikiHome/Articles/111111284

9)很不错的文档下载:http://www.intel.com/cd/ids/developer/asmo-na/eng/dc/threading/knowledgebase/20439.htm

10)msdn上所有的线程同步API介绍:http://msdn2.microsoft.com/en-us/library/ms686360.aspx


线程同步API:(来自msdn)

 
Asynchronous function Description
APCProc An application-defined callback function used with the QueueUserAPC function.
GetOverlappedResult Retrieves the results of an overlapped operation.
QueueUserAPC Adds a user-mode asynchronous procedure call (APC) object to the APC queue of the specified thread.

Condition variable and SRW lock function Description
AcquireSRWLockExclusive Acquires a slim reader/writer (SRW) lock in exclusive mode.
AcquireSRWLockShared Acquires a slim reader/writer (SRW) lock in shared mode.
InitializeConditionVariable Initializes a condition variable.
InitializeSRWLock Initialize a slim reader/writer (SRW) lock.
ReleaseSRWLockExclusive Releases a slim reader/writer (SRW) lock that was acquired in exclusive mode.
ReleaseSRWLockShared Releases a slim reader/writer (SRW) lock that was acquired in shared mode.
SleepConditionVariableCS Sleeps on the specified condition variable and releases the specified critical section as an atomic operation.
SleepConditionVariableSRW Sleeps on the specified condition variable and releases the specified lock as an atomic operation.
WakeAllConditionVariable Wake all threads waiting on the specified condition variable.
WakeConditionVariable Wake a single thread waiting on the specified condition variable.

Critical-section function Description
DeleteCriticalSection Releases all resources used by an unowned critical section object.
EnterCriticalSection Waits for ownership of the specified critical section object.
InitializeCriticalSection Initializes a critical section object.
InitializeCriticalSectionAndSpinCount Initializes a critical section object and sets the spin count for the critical section.
InitializeCriticalSectionEx Initializes a critical section object with a spin count and optional flags.
LeaveCriticalSection Releases ownership of the specified critical section object.
SetCriticalSectionSpinCount Sets the spin count for the specified critical section.
TryEnterCriticalSection Attempts to enter a critical section without blocking.

Event function Description
CreateEvent Creates or opens a named or unnamed event object.
CreateEventEx Creates or opens a named or unnamed event object and returns a handle to the object.
OpenEvent Opens an existing named event object.
PulseEvent Sets the specified event object to the signaled state and then resets it to the nonsignaled state after releasing the appropriate number of waiting threads.
ResetEvent Sets the specified event object to the nonsignaled state.
SetEvent Sets the specified event object to the signaled state.

One-time Initialization function Description
InitOnceBeginInitialize Begins one-time initialization.
InitOnceComplete Completes one-time initialization.
InitOnceExecuteOnce Executes the specified function successfully one time. No other threads that specify the same one-time initialization structure can execute this function while it is being executed by the current thread.
InitOnceInitialize Initializes a one-time initialization structure.

Interlocked function Description
InterlockedAdd Performs an atomic addition operation on the specified LONG values.
InterlockedAdd64 Performs an atomic addition operation on the specified LONGLONG values.
InterlockedAddAcquire Performs an atomic addition operation on the specified LONG values. The operation is performed with acquire memory access semantics.
InterlockedAddAcquire64 Performs an atomic addition operation on the specified LONGLONG values. The operation is performed with acquire memory access semantics.
InterlockedAddRelease Performs an atomic addition operation on the specified LONG values. The operation is performed with release memory access semantics.
InterlockedAddRelease64 Performs an atomic addition operation on the specified LONGLONG values. The operation is performed with release memory access semantics.
InterlockedAnd Performs an atomic AND operation on the specified LONG values.
InterlockedAndAcquire Performs an atomic AND operation on the specified LONG values. The operation is performed with acquire memory access semantics.
InterlockedAndRelease Performs an atomic AND operation on the specified LONG values. The operation is performed with release memory access semantics.
InterlockedAnd8 Performs an atomic AND operation on the specified char values.
InterlockedAnd8Acquire Performs an atomic AND operation on the specified char values. The operation is performed with acquire memory access semantics.
InterlockedAnd8Release Performs an atomic AND operation on the specified char values. The operation is performed with release memory access semantics.
InterlockedAnd16 Performs an atomic AND operation on the specified SHORT values.
InterlockedAnd16Acquire Performs an atomic AND operation on the specified SHORT values. The operation is performed with acquire memory access semantics.
InterlockedAnd16Release Performs an atomic AND operation on the specified SHORT values. The operation is performed with release memory access semantics.
InterlockedAnd64 Performs an atomic AND operation on the specified LONGLONG values.
InterlockedAnd64Acquire Performs an atomic AND operation on the specified LONGLONG values. The operation is performed with acquire memory access semantics.
InterlockedAnd64Release Performs an atomic AND operation on the specified LONGLONG values. The operation is performed with release memory access semantics.
InterlockedBitTestAndReset Tests the specified bit of the specified LONG value and sets it to 0.
InterlockedBitTestAndReset64 Tests the specified bit of the specified LONG64 value and sets it to 0.
InterlockedBitTestAndSet Tests the specified bit of the specified LONG value and sets it to 1.
InterlockedBitTestAndSet64 Tests the specified bit of the specified LONG64 value and sets it to 1.
InterlockedCompare64Exchange128 Performs an atomic compare-and-exchange operation on the specified values. The function compares the specified 64-bit values and exchanges with the specified 128-bit value based on the outcome of the comparison.
InterlockedCompare64ExchangeAcquire128 Performs an atomic compare-and-exchange operation on the specified values. The function compares the specified 64-bit values and exchanges with the specified 128-bit value based on the outcome of the comparison. The operation is performed with acquire memory access semantics.
InterlockedCompare64ExchangeRelease128 Performs an atomic compare-and-exchange operation on the specified values. The function compares the specified 64-bit values and exchanges with the specified 128-bit value based on the outcome of the comparison. The operation is performed with release memory access semantics.
InterlockedCompareExchange Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 32-bit values and exchanges with another 32-bit value based on the outcome of the comparison.
InterlockedCompareExchange64 Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 64-bit values and exchanges with another 64-bit value based on the outcome of the comparison.
InterlockedCompareExchangeAcquire Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 32-bit values and exchanges with another 32-bit value based on the outcome of the comparison. The operation is performed with acquire memory access semantics.
InterlockedCompareExchangeAcquire64 Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 64-bit values and exchanges with another 64-bit value based on the outcome of the comparison. The exchange is performed with acquire memory access semantics.
InterlockedCompareExchangePointer Performs an atomic compare-and-exchange operation on the specified pointer values. The function compares two specified pointer values and exchanges with another pointer value based on the outcome of the comparison.
InterlockedCompareExchangePointerAcquire Performs an atomic compare-and-exchange operation on the specified pointer values. The function compares two specified pointer values and exchanges with another pointer value based on the outcome of the comparison. The operation is performed with acquire memory access semantics.
InterlockedCompareExchangePointerRelease Performs an atomic compare-and-exchange operation on the specified pointer values. The function compares two specified pointer values and exchanges with another pointer value based on the outcome of the comparison. The operation is performed with release memory access semantics.
InterlockedCompareExchangeRelease Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 32-bit values and exchanges with another 32-bit value based on the outcome of the comparison. The exchange is performed with release memory access semantics.
InterlockedCompareExchangeRelease64 Performs an atomic compare-and-exchange operation on the specified values. The function compares two specified 64-bit values and exchanges with another 64-bit value based on the outcome of the comparison. The exchange is performed with release memory access semantics.
InterlockedDecrement Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation.
InterlockedDecrement64 Decrements (decreases by one) the value of the specified 64-bit variable as an atomic operation.
InterlockedDecrementAcquire Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation. The operation is performed with acquire memory access semantics.
InterlockedDecrementAcquire64 Decrements (decreases by one) the value of the specified 64-bit variable as an atomic operation. The operation is performed with acquire memory access semantics.
InterlockedDecrementRelease Decrements (decreases by one) the value of the specified 32-bit variable as an atomic operation. The operation is performed with release memory access semantics.
InterlockedDecrementRelease64 Decrements (decreases by one) the value of the specified 64-bit variable as an atomic operation. The operation is performed with release memory access semantics.
InterlockedExchange Sets a 32-bit variable to the specified value as an atomic operation.
InterlockedExchange64 Sets a 64-bit variable to the specified value as an atomic operation.
InterlockedExchangeAcquire Sets a 32-bit variable to the specified value as an atomic operation. The operation is performed with acquire memory access semantics.
InterlockedExchangeAcquire64 Sets a 32-bit variable to the specified value as an atomic operation. The operation is performed with acquire memory access semantics.
InterlockedExchangeAdd Performs an atomic addition of two 32-bit values.
InterlockedExchangeAdd64 Performs an atomic addition of two 64-bit values.
InterlockedExchangeAddAcquire Performs an atomic addition of two 32-bit values. The operation is performed with acquire memory access semantics.
InterlockedExchangeAddAcquire64 Performs an atomic addition of two 64-bit values. The operation is performed with acquire memory access semantics.
InterlockedExchangeAddRelease Performs an atomic addition of two 32-bit values. The operation is performed with release memory access semantics.
InterlockedExchangeAddRelease64 Performs an atomic addition of two 64-bit values. The operation is performed with release memory access semantics.
InterlockedExchangePointer Atomically exchanges a pair of pointer values.
InterlockedExchangePointerAcquire Atomically exchanges a pair of pointer values. The operation is performed with acquire memory access semantics.
InterlockedIncrement Increments (increases by one) the value of the specified 32-bit variable as an atomic operation.
InterlockedIncrement64 Increments (increases by one) the value of the specified 64-bit variable as an atomic operation.
InterlockedIncrementAcquire Increments (increases by one) the value of the specified 32-bit variable as an atomic operation. The operation is performed using acquire memory access semantics.
InterlockedIncrementAcquire64 Increments (increases by one) the value of the specified 64-bit variable as an atomic operation. The operation is performed using acquire memory access semantics.
InterlockedIncrementRelease Increments (increases by one) the value of the specified 32-bit variable as an atomic operation. The operation is performed using release memory access semantics.
InterlockedIncrementRelease64 Increments (increases by one) the value of the specified 64-bit variable as an atomic operation. The operation is performed using release memory access semantics.
InterlockedOr Performs an atomic OR operation on the specified LONG values.
InterlockedOrAcquire Performs an atomic OR operation on the specified LONG values. The operation is performed with acquire memory access semantics.
InterlockedOrRelease Performs an atomic OR operation on the specified LONG values. The operation is performed with release memory access semantics.
InterlockedOr8 Performs an atomic OR operation on the specified char values.
InterlockedOr8Acquire Performs an atomic OR operation on the specified char values. The operation is performed with acquire memory access semantics.
InterlockedOr8Release Performs an atomic OR operation on the specified char values. The operation is performed with release memory access semantics.
InterlockedOr16 Performs an atomic OR operation on the specified SHORT values.
InterlockedOr16Acquire Performs an atomic OR operation on the specified SHORT values. The operation is performed with acquire memory access semantics.
InterlockedOr16Release Performs an atomic OR operation on the specified SHORT values. The operation is performed with release memory access semantics.
InterlockedOr64 Performs an atomic OR operation on the specified LONGLONG values.
InterlockedOr64Acquire Performs an atomic OR operation on the specified LONGLONG values. The operation is performed with acquire memory access semantics.
InterlockedOr64Release Performs an atomic OR operation on the specified LONGLONG values. The operation is performed with release memory access semantics.
InterlockedXor Performs an atomic XOR operation on the specified LONG values.
InterlockedXorAcquire Performs an atomic XOR operation on the specified LONG values. The operation is performed with acquire memory access semantics.
InterlockedXorRelease Performs an atomic XOR operation on the specified LONG values. The operation is performed with release memory access semantics.
InterlockedXor8 Performs an atomic XOR operation on the specified char values.
InterlockedXor8Acquire Performs an atomic XOR operation on the specified char values. The operation is performed with acquire memory access semantics.
InterlockedXor8Release Performs an atomic XOR operation on the specified char values. The operation is performed with release memory access semantics.
InterlockedXor16 Performs an atomic XOR operation on the specified SHORT values.
InterlockedXor16Acquire Performs an atomic XOR operation on the specified SHORT values. The operation is performed with acquire memory access semantics.
InterlockedXor16Release Performs an atomic XOR operation on the specified SHORT values. The operation is performed with release memory access semantics.
InterlockedXor64 Performs an atomic XOR operation on the specified LONGLONG values.
InterlockedXor64Acquire Performs an atomic XOR operation on the specified LONGLONG values. The operation is performed with acquire memory access semantics.
InterlockedXor64Release Performs an atomic XOR operation on the specified LONGLONG values. The operation is performed with release memory access semantics.

Mutex function Description
CreateMutex Creates or opens a named or unnamed mutex object.
CreateMutexEx Creates or opens a named or unnamed mutex object and returns a handle to the object.
OpenMutex Opens an existing named mutex object.
ReleaseMutex Releases ownership of the specified mutex object.

Namespace function Description
AddSIDToBoundaryDescriptor Adds a new security identifier (SID) to the specified boundary descriptor.
ClosePrivateNamespace Closes an open namespace handle.
CreateBoundaryDescriptor Creates a boundary descriptor.
CreatePrivateNamespace Creates a private namespace.
DeleteBoundaryDescriptor Deletes the specified boundary descriptor.
OpenPrivateNamespace Opens a private namespace.

Semaphore function Description
CreateSemaphore Creates or opens a named or unnamed semaphore object.
CreateSemaphoreEx Creates or opens a named or unnamed semaphore object and returns a handle to the object.
OpenSemaphore Opens an existing named semaphore object.
ReleaseSemaphore Increases the count of the specified semaphore object by a specified amount.

Singly-linked list function Description
InitializeSListHead Initializes the head of a singly linked list.
InterlockedFlushSList Flushes the entire list of items in a singly linked list.
InterlockedPopEntrySList Removes an item from the front of a singly linked list.
InterlockedPushEntrySList Inserts an item at the front of a singly linked list.
QueryDepthSList Retrieves the number of entries in the specified singly linked list.
RtlFirstEntrySList Retrieves the first entry in a singly linked list.
RtlInitializeSListHead Initializes the head of a singly linked list. Applications should call InitializeSListHead instead.
RtlInterlockedFlushSList Flushes the entire list of items in a singly linked list. Applications should call InterlockedFlushSList instead.
RtlInterlockedPopEntrySList Removes an item from the front of a singly linked list. Applications should call InterlockedPopEntrySList instead.
RtlInterlockedPushEntrySList Inserts an item at the front of a singly linked list. Applications should call InterlockedPushEntrySList instead.
RtlQueryDepthSList Retrieves the number of entries in the specified singly linked list. Applications should call QueryDepthSList instead.

Timer-queue timer function Description
ChangeTimerQueueTimer Updates a timer-queue timer.
CreateTimerQueue Creates a queue for timers.
CreateTimerQueueTimer Creates a timer-queue timer.
DeleteTimerQueue Deletes a timer queue.
DeleteTimerQueueEx Deletes a timer queue.
DeleteTimerQueueTimer Cancels a timer-queue timer.

Wait function Description
MsgWaitForMultipleObjects Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses. The objects can include input event objects.
MsgWaitForMultipleObjectsEx Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses. The array of objects can include input event objects.
RegisterWaitForSingleObject Directs a wait thread in the thread pool to wait on the object.
SignalObjectAndWait Atomically signals one object and waits on another object.
UnregisterWait Cancels a registered wait operation.
UnregisterWaitEx Cancels a registered wait operation.
WaitForMultipleObjects Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
WaitForMultipleObjectsEx Waits until one or all of the specified objects are in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
WaitForSingleObject Waits until the specified object is in the signaled state or the time-out interval elapses.
WaitForSingleObjectEx Waits until the specified object is in the signaled state, an I/O completion routine or asynchronous procedure call (APC) is queued to the thread, or the time-out interval elapses.
WaitOrTimerCallback An application-defined function that serves as the starting address for a timer callback or a registered wait callback.

Waitable-timer function Description
CancelWaitableTimer Sets the specified waitable timer to the inactive state.
CreateWaitableTimer Creates or opens a waitable timer object.
CreateWaitableTimerEx Creates or opens a waitable timer object and returns a handle to the object.
OpenWaitableTimer Opens an existing named waitable timer object.
SetWaitableTimer Activates the specified waitable timer.
TimerAPCProc Application-defined timer completion routine used with the SetWaitableTimer function.


posted on 2007-03-16 17:12 梦在天涯 阅读(11979) 评论(1)  编辑 收藏 引用 所属分类: CPlusPlus

评论

# re: c++的多线程编程(资料收集) 2007-03-17 08:52 Galaxy_Yang

最近的工作中遇到了多线程的问题,
就是http异步多线程下载, 总是有一个线程获得的CPU的时间不多,
其他线程都结束了, 整个文件的下载过程得等最后一个线程下完才行,不知道
flashget和thunder是怎么做到基本上多个线程是同时结束的?

想和你探讨以下多线程编程的问题

  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1796890
  • 排名 - 5

最新评论

阅读排行榜