Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 并行foreach和SyncLock在目标cpu x86中不工作_Vb.net - Fatal编程技术网

Vb.net 并行foreach和SyncLock在目标cpu x86中不工作

Vb.net 并行foreach和SyncLock在目标cpu x86中不工作,vb.net,Vb.net,我在VB.Net中使用了并行ForEach和SyncLock 这是我的密码: Parallel.ForEach(Collection, Sub(p) 'do something If List.Any(Function(x) x.Field1 = headers(0)) Then SyncLock _SyncObject Dim current = List.First(Function(x) x.Field1 = head

我在VB.Net中使用了并行ForEach和SyncLock

这是我的密码:

Parallel.ForEach(Collection, Sub(p)
     'do something 
     If List.Any(Function(x) x.Field1 = headers(0)) Then
          SyncLock _SyncObject
               Dim current = List.First(Function(x) x.Field1 = headers(0))
               'do something
          End SyncLock

     End If
End Sub)
此代码在64位操作系统中成功执行。但在32位操作系统中,它不起作用

该代码引发一个异常,该异常发生在数据集设计器中:

索引超出了数组的边界

例外情况发生在以下位置:

   <Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
     Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")>  _
    Public Property FromMVar() As String
        Get
            Try 
                **Return CType(Me(Me.tablemyTable.Field1Column),String)**
            Catch e As Global.System.InvalidCastException
                Throw New Global.System.Data.StrongTypingException("The value for column 'Field1' in table 'myTable' is DBNull.", e)
            End Try
        End Get
        Set
            Me(Me.tableLinesFile.FromMVarColumn) = value
        End Set
    End Property

我尝试使用目标cpu 86、64的所有状态,以及任何cpu。如何在OS 32上解决此问题?

至少有一个线程竞赛错误显而易见,可能不止一个。当List.Any返回True,然后你得到一个锁,那么你不能保证List.Any仍然为True。您必须移动列表。SyncLock语句中的任何调用也必须移动。当然,这完全违背了使用并行的观点。32和64之间的区别是什么?为什么它能在OS 64中工作?线程竞赛bug有很强的隐藏自己的技巧,它们严重依赖于时间。而64位代码的运行方式与32位代码不同,它通常要慢一点。这并不意味着bug不存在,只是意味着您还没有进行足够长的测试。有些种族细菌一个月只发生一次,很难诊断。