This file includes the listings for Matt Curland's June 1999 Black Belt Programming column, "Create Worker Threads in DLLs."


Listing 1

'Code in ThreadStart procedure
ThreadStart = TL.Go(TC, ThreadDataCookie)
EnterCriticalSection pCritSect
InterlockedIncrement ThreadDonePointer
LeaveCriticalSection pCritSect
Set TL = Nothing

'Code in ThreadData class
Friend Sub SignalThread(ByVal pCritSect As Long, _
	ByRef fInCriticalSection As Boolean)
If m_ThreadSignal Then
	If Not fInCriticalSection Then
		EnterCriticalSection pCritSect
		fInCriticalSection = True
'LeaveCriticalSection is called by ThreadControl to 
'enable multiple signals to be sent without thrashing
'the synchronization object.
	End If
'Only signal if the thread isn't done
	If m_ThreadDone = 0 Then
		InterlockedIncrement m_ThreadSignal
	End If
'Only one signal needed
	m_ThreadSignal = 0
End If
End Sub

