SIGSEGV与UnixSignal.WaitAny()

时间:2015-10-29 09:50:53

标签: c# mono raspberry-pi2

我是Mono的新人。我使用Mono.Posix lib来处理Raspbian信号。昨天一切都很好,但今天它崩溃了,我无法找到任何解决方案。 它编译得很好,但在WaitAny()上崩溃了:

            new Thread(() =>
                {
                    var signals = new[]
                    {
                        new UnixSignal(Signum.SIGINT),
                        new UnixSignal(Signum.SIGUSR1)
                    };

                    UnixSignal.WaitAny(signals, -1);

                }).Start();

这是stacktrace:

堆栈跟踪:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Mono.Unix.UnixSignal.WaitAny (intptr[],int,int) <IL 0x00042, 0xffffffff>
  at Mono.Unix.UnixSignal.WaitAny (Mono.Unix.UnixSignal[],int) <IL 0x00076, 0x002ff>
  at CarWashInterop.Program.<StartExitHandler>m__1 () [0x0001d] in /home/pi/CarWashInterop/CarWashInterop/Program.cs:66
  at System.Threading.Thread.StartInternal () <IL 0x00021, 0x000f3>
  at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <IL 0x0005e, 0xffffffff>

Native stacktrace:


Debug info from gdb:

[New LWP 1873]
[New LWP 1872]
[New LWP 1868]
[New LWP 1867]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
0x76e9c7a4 in __pthread_cond_wait (cond=0x82a8a0, mutex=0x82a884) at pthread_cond_wait.c:187
187 pthread_cond_wait.c: No such file or directory.
  Id   Target Id         Frame 
  5    Thread 0x76a63430 (LWP 1867) "Finalizer" 0x76e9ea40 in do_futex_wait (isem=isem@entry=0x22a81c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
  4    Thread 0x76963430 (LWP 1868) "mono" 0x76ea00c0 in recv () at ../sysdeps/unix/syscall-template.S:81
  3    Thread 0x74d6a430 (LWP 1872) "mono" 0x76de5824 in ___xstat64 (vers=<optimized out>, name=<optimized out>, buf=0x74d69168) at ../sysdeps/unix/sysv/linux/xstat64.c:35
  2    Thread 0x74aff430 (LWP 1873) "mono" 0x76ea0ee8 in __libc_waitpid (pid=1874, stat_loc=0x74afe0d4, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
* 1    Thread 0x76fb3000 (LWP 1865) "mono" 0x76e9c7a4 in __pthread_cond_wait (cond=0x82a8a0, mutex=0x82a884) at pthread_cond_wait.c:187

Thread 5 (Thread 0x76a63430 (LWP 1867)):
#0  0x76e9ea40 in do_futex_wait (isem=isem@entry=0x22a81c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:48
#1  0x76e9eaf4 in __new_sem_wait (sem=0x22a81c) at ../nptl/sysdeps/unix/sysv/linux/sem_wait.c:69
#2  0x001619e4 in mono_sem_wait ()
#3  0x0010ee0a in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 4 (Thread 0x76963430 (LWP 1868)):
#0  0x76ea00c0 in recv () at ../sysdeps/unix/syscall-template.S:81
#1  0x0009e62e in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 3 (Thread 0x74d6a430 (LWP 1872)):
#0  0x76de5824 in ___xstat64 (vers=<optimized out>, name=<optimized out>, buf=0x74d69168) at ../sysdeps/unix/sysv/linux/xstat64.c:35
#1  0x0014f226 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 2 (Thread 0x74aff430 (LWP 1873)):
#0  0x76ea0ee8 in __libc_waitpid (pid=1874, stat_loc=0x74afe0d4, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x00088020 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 1 (Thread 0x76fb3000 (LWP 1865)):
#0  0x76e9c7a4 in __pthread_cond_wait (cond=0x82a8a0, mutex=0x82a884) at pthread_cond_wait.c:187
#1  0x0014b622 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
bash: line 1: 2375 Aborted 'usr/bin/mono' --debug --debugger-agent=transport=dt_socket,address=127.0.0.1:57263 "/home/pi/.../CarWashInterop.exe"

这种行为可能是什么原因?

UPD:它只在Debug中崩溃,Release很好用。

1 个答案:

答案 0 :(得分:1)

检查是否为项目选择了启用优化。如果取消选中启用优化,则不会发生崩溃,信号处理也很好。它接收终止信号