我正在使用SSDeepfuzzy.dll
對大量文件執行模糊散列。在多線程應用程序中使用非線程安全的DLL
如果我依次運行哈希,它一切正常。如果我嘗試使用多線程,它會下降(該應用程序終止,沒有例外信息,並在日誌中沒有任何內容)
我假設該DLL不是線程安全的,並且一個線程試圖讀取另一個的內存或類似的東西。
我想要做的就是讓每個線程都擁有自己的dll副本。請注意,這不是一個實例 - 它全部是靜態的/共享的 - 我只是想模擬如果引用dll的兩個進程同時運行會發生什麼 - 它們會擁有自己的內存空間等等。 ..
這可能沒有實際產卵多個進程?
<DllImport("C:\SSDeep\Fuzzy.dll",
EntryPoint:="fuzzy_hash_filename",
CallingConvention:=CallingConvention.Cdecl)>
Private Shared Function fuzzy_hash_filename(
<InAttribute(),
MarshalAsAttribute(UnmanagedType.LPStr)>
ByVal Filename As String,
ByVal Result As StringBuilder) As Integer
End Function
Public Shared Function FuzzyHash(Filename As String) As String
Dim Ret As New StringBuilder
Ret.Capacity = NativeConstants.FUZZY_MAX_RESULT
Dim Success = fuzzy_hash_filename(Filename, Ret)
If Success <> 0 Then
Throw New Exception("SSDeep fuzzy hashing failed")
End If
Return Ret.ToString
End Function
沒有什麼聰明的,我可以用應用程序域或西米做LAR?奇怪的是,多個副本的dll實際上可能比多個進程更可取,但我需要生成inter-on-the-fly。我沒有考慮過 – Basic 2012-08-07 12:23:42