mao1278 发表于 2009-3-4 09:59:32

ACE_Thread_Semaphore在ARM上应用release时被阻塞

我用的ACE版本为5.6的,我ARM上裁减的为2.6的内核.我的应用程序在编译后,在X86的Linux环境下运行无问题,但是移植到ARM上后,一运行到release()处,则被阻塞.不知道什么原因,望高手帮忙解决下....谢谢哈.附代码如下
PS:先猜测几种出错的可能:
1.应用程序上的错误.
2.ace库在移植后的错误.
3.交叉编译环境的错误.
4.arm上操作系统的错误.
望各位高手帮忙分析下...

#include "ace/Synch.h"
#include "ace/Thread_Manager.h"
#include "ace/OS.h"
class CTest_Semaphore
{
public:
CTest_Semaphore() : sp_data(0)
{
bisstop = false;
bisexit = false;
}
~CTest_Semaphore()
{
}
static int worker(void* p)
{
CTest_Semaphore* lp = (CTest_Semaphore*)p;
while (!lp->bisexit)
{
   if (!lp->bisstop)
   {
    printf("I am worker !\n");
    lp->sp_data.release();                // 运行在这里被阻塞.......
   }
   ACE_OS::sleep(1);
}
return 0;
}
static int consumer(void* p)
{
CTest_Semaphore* lp = (CTest_Semaphore*)p;
while(!lp->bisexit)
{
   lp->sp_data.acquire();
   printf("I am consumer !\n");
}
return 0;
}
void open()
{
ACE_Thread_Manager::instance()->spawn((ACE_THR_FUNC)worker, this);
ACE_Thread_Manager::instance()->spawn((ACE_THR_FUNC)consumer, this);
}
void close()
{
ACE_Thread_Manager::instance()->wait();
}
public:
bool bisstop;
bool bisexit;
ACE_Thread_Semaphore sp_data;
};
int ACE_TMAIN(int argc, char* argv[])
{
CTest_Semaphore cts;
cts.open();

while(1)
{
char ch = getchar();

if (ch == 'q')
{
   cts.bisexit = true;
   cts.sp_data.release();
   break;
}
else if (ch == 's')
{
   cts.bisstop = !cts.bisstop;
}
}
cts.close();
return 0;
}

[ 本帖最后由 mao1278 于 2009-3-4 14:34 编辑 ]

winston 发表于 2009-3-4 14:17:31

有问题:
while (!lp->bisexit)

bool bisstop; //- 没有访问保护
bool bisexit; //- 没有访问保护

用:
ACE_Atomic_Op<ACE_Thread_Mutex,bool> xxx;

mao1278 发表于 2009-3-4 14:39:33

原帖由 winston 于 2009-3-4 14:17 发表 http://www.acejoy.com/bbs/images/common/back.gif
有问题:
while (!lp->bisexit)

bool bisstop; //- 没有访问保护
bool bisexit; //- 没有访问保护

用:
ACE_Atomic_Op xxx;

对这两个变量的操作应该都为原子操作吧...

主要是出错的地方不在这里...而是ACE_Thread_Semaphore的对象sp_data,在arm平台上,运行到sp_data.release()时即阻塞在那里了....

我主要想知道的是为什么ACE_Thread_Semaphore的问题...同样的代码在X86架构下运行无误.而移植到arm后就阻塞在那里了....我想知道问题出在哪里了...:'(

[ 本帖最后由 mao1278 于 2009-3-4 14:42 编辑 ]

winston 发表于 2009-3-4 16:57:06

有时候现象并不是本质,你先改正掉发现的错误,再测试一遍看看结果。

mao1278 发表于 2009-3-4 17:37:34

问题解决了...我重新换了个ACE版本,用的是5.6.8的版本,在ARM上运行没有出现问题

难道是以前5.6.0版本中的ACE_Thread_Semaphore的实现有问题?

再研究下这两个版本的代码先

winston 发表于 2009-3-4 22:39:06

完全有可能!你对比一下实现吧。

chris_liu 发表于 2009-5-30 14:00:34

原帖由 mao1278 于 2009-3-4 17:37 发表 http://www.acejoy.com/bbs/images/common/back.gif
问题解决了...我重新换了个ACE版本,用的是5.6.8的版本,在ARM上运行没有出现问题

难道是以前5.6.0版本中的ACE_Thread_Semaphore的实现有问题?

再研究下这两个版本的代码先 ...

请问这两个版本的实现有什么不同?
ACE_Thread_Semaphore只是简单的封装吧.
页: [1]
查看完整版本: ACE_Thread_Semaphore在ARM上应用release时被阻塞