我们尝试在Net Bsd 7.0(amd64)上移植虚拟机。已经成功地从Linux移植到Free BSD和Open BSD。关于Net BSD的全新和标准安装,我们有几个问题。


使用gcc和以下标志编译代码:
CC_OPTIONS = -pedantic -Wall -Wno-trigraphs -Wno-long-long -Wno-variadic-macros -fshort-wchar -x c ++ -fPIC -pipe -fno-omit-frame-pointer -g -I“ / usr / local “ / include -I” $(UAS_SRC)“
LD_OPTIONS = -shared-libgcc -L“ / usr / lib” -L“ / usr / local / lib” -L“ $(UAS_HOME)vtm / lib”
尝试使用pthread_create()创建线程时,该进程从libc运行时接收SIGABRT:
gdb backtrace:


在/usr/lib/libc.so.12的_lwp_kill()中
在/usr/lib/libc.so.12中的__lwd_thr_create_stub()中
在/usr/libpthread.so.1的_pthread_create()中
在/home/../syspsx_nt.cpp中的CreerThread2()中

尝试使用自旋锁时,我们收到段冲突。这是测试用例:

typedef struct typmttsysnatsynchronisationdirect
{
联盟

   {
   pthread_spinlock_t HandleSpinLock;
   }选择;

} * TypMttSysNatSynchronisationDirect;

TypMttSysNatSynchronisationDirect SynchronisationCourant;
int响应;

SynchronisationCourant =(TypMttSysNatSynchronisationDirect)malloc(sizeof(struct typmttsysnatsynchronisationdirect));;
如果(SynchronisationCourant == NULL)

   返回(0);

memset(SynchronisationCourant,0x0,sizeof(struct typmttsysnatsynchronisationdirect));;
响应= pthread_spin_init(&(SynchronisationCourant-> Selection.HandleSpinLock),PTHREAD_PROCESS_SHARED);
如果(响应!= 0)

   返回(0);

响应= pthread_spin_lock(&(SynchronisationCourant-> Selection.HandleSpinLock));
如果(响应!= 0)

   返回(0);



在反汇编pthread_spin_init()和pthread_spin_lock()的代码时,似乎在pthread_spinlock内部有一个函数指针,该函数指针在pthread_spin_init()中设置为NULL,并间接调用到pthread_spintrylock()中,而该指针由pthread_spinlock()调用。

感谢您的帮助。

最佳答案

似乎每个模块都由编译器(gcc)标记为与多线程兼容或不兼容,并且所生成的代码略有改动。而且,您不能将两种模块混合到一个可执行文件中。特别是如果您使用dlopen()动态加载某些共享库。

由于msvc有/ Mt选项,因此gcc的-rethread是-pthread,但对于Net BSD不可用。它在其他平台上没有用。

解决方法是系统地将libpthread.so链接到每个模块。然后标记每个模块具有兼容的多线程。
两个问题都结束了。

关于c - netbsd pthread_create SIGABRT,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40020505/

10-09 08:40