平行进入睡眠状态

时间:2017-08-08 14:14:29

标签: f# mono gdb sleep

我正在运行一些用F#编写的单声道代码,我看到在运行一段时间后(几周),某些进程处于睡眠模式。使用strace作为strace -p <pid>我得到

Process 38756 attached - interrupt to quit
futex(0x272ee9c, FUTEX_WAIT_PRIVATE, 1, NULL

据我了解,这意味着某些部分正在等待某些事情(其他线程)。 所以我继续用gdb attach <pid>搜索问题,其中我可以看到有4个线程:

(gdb) info threads
 4 Thread 0x7ff06a3ff700 (LWP 38760)  0x0000003b3c80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
 3 Thread 0x7ff06aa17700 (LWP 38769)  0x0000003b3c80d930 in sem_wait () from /lib64/libpthread.so.0
 2 Thread 0x7ff0677ff700 (LWP 38789)  0x0000003b3c80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 1 Thread 0x7ff070a07760 (LWP 38756)  0x0000003b3c80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0

在线程1上使用where我可以看到它不起作用的地方是Parallel.For()

就我而言,进程进入休眠状态的代码是:

let sinMod t (difRay:Vector) (fA:(float*Vector*float)[]) =
  let duepi = 2.*PI

  Array.fold(fun acc x -> let freq, amplitude, phase = fA.[x]
                        acc+sin(duepi*freq*t+phase)*(amplitude*difRay)) 0. [|0..fA.Length-1|] 

let NextFunc (var1:type1,var2:type2,var3:type3) =
  // do some stuff
  ...
  // some context
  let time = snd var3
  let inputArray = var.SomeArray // float[]

  // the function that doesn't works
  Parallel.For(0, (inputArray .Length), fun i -> (inputArray .[i] <- inputArray .[i]+(ww*SINMOD time.[i])) ) |> ignore

  inputArray  // return from NextFunc 

我真的不知道问题出在哪里。有时这个过程会进入睡眠状态而其他情况则不会发生。我不知道这是否可以有任何关系,但parallel.for的长度是40960

为什么程序要睡觉?

谢谢

编辑: 我没有说明为什么我认为这个问题正如我所说的那样发生。使用gdb我获得:

(gdb) where
#0  0x0000003b3c80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x000000000060cd0d in mono_os_cond_wait (cond=0x272ee98, mutex=0x272ee70, timeout_ms=4294967295) at ../../mono/utils/mono-os-mutex.h:105
#2  mono_os_cond_timedwait (cond=0x272ee98, mutex=0x272ee70, timeout_ms=4294967295) at ../../mono/utils/mono-os-mutex.h:120
#3  0x000000000060f0c8 in _wapi_handle_timedwait_signal_handle (handle=0x410, timeout=4294967295, alertable=1, poll=0, alerted=0x7fff27d2a6cc)
at handles.c:1554
#4  0x00000000006245ea in wapi_WaitForSingleObjectEx (handle=0x410, timeout=4294967295, alertable=1) at wait.c:173
#5  0x00000000005b01f2 in ves_icall_System_Threading_Monitor_Monitor_wait (obj=0x7fed09df4cc0, ms=4294967295) at monitor.c:1294
#6  0x00007ff06806385e in System.Threading.Monitor:Wait (obj=<type 'exceptions.ValueError'>
zero length field name in format
140656049605824, millisecondsTimeout=-1) at /root/mono-4.3.2/mcs/class/corlib/System.Threading/Monitor.cs:148
#7  0x00007ff067e69dc2 in System.Threading.ManualResetEventSlim:Wait (this=..., millisecondsTimeout=-1, cancellationToken=0)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/ManualResetEventSlim.cs:669
#8  0x00007ff067e8544e in System.Threading.Tasks.Task:SpinThenBlockingWait (this=..., millisecondsTimeout=-1, cancellationToken=0)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:3326
#9  0x00007ff067e8255d in System.Threading.Tasks.Task:InternalRunSynchronously (this=..., scheduler=..., waitForCompletion=true)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:1231
#10 0x00007ff067e823c8 in System.Threading.Tasks.Task:RunSynchronously (this=..., scheduler=...)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:1169
#11 0x00007ff067e77c03 in System.Threading.Tasks.Parallel:ForWorker<TLocal_REF> (fromInclusive=0, toExclusive=40960, parallelOptions=..., body=...,
bodyWithState=..., bodyWithLocal=..., localInit=..., localFinally=...)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/Tasks/Parallel.cs:1273
#12 0x00007ff067e76b8a in System.Threading.Tasks.Parallel:For (fromInclusive=0, toExclusive=40960, body=...)
at /root/mono-4.3.2/external/referencesource/mscorlib/system/threading/Tasks/Parallel.cs:441
#13 0x00000000402c11ee in ?? ()
#14 0x00007fff27d2aec0 in ?? ()
#15 0x00007ff0167eab00 in ?? () 
#16 0x0000000000000016 in ?? ()
#17 0x00007fef394db070 in ?? ()
#18 0x0000000000000000 in ?? ()
(gdb) p mono_pmip(0x00000000402c11ee)
$1 =
    0x29ae0f0 " ShadingNoise:PhaseModulation (Types.types/Ray,Types.types/Intersection,System.Tuple`2<System.Tuple`3<double, Types.Algebra/Vector, double>[], double[]>) + 0x27e (0x402c0f70 0x402c1238) [0x273b080 - m"...
(gdb)

在哪里指定, ShadingNoise:PhaseModulation 是我以简化方式定义为 NextFunc 的函数。以防万一,原来的功能是here

0 个答案:

没有答案