游戏退出后linux系统崩溃

发布于 2024-10-27 15:41:36 字数 874 浏览 2 评论 0原文

我在电视的linux系统上运行我的游戏,当我退出游戏时,系统会崩溃。

从输出日志中,我知道我的游戏已经相当了,但是系统崩溃了。

主要功能如下:

int main(int argc, char** argv)
{
 ......

 SDL_Quit();

 printf("Log: exit end. \n);// it's printed on console
 return 0;
}

我可以找到有关 Log: exit end 的输出日志。那么游戏已经退出了吧?

我发现游戏退出只会在创建线程后崩溃。

这是下面线程中的 run 函数:

   while ( pThread->m_running )
    {
        string str;
        string cmdStr;

        if ( pThread->GetSendMsg(str, cmdStr) )
        {
            string returnStr = Connection::DealHttpSendMsg( str, cmdStr );

            pThread->AddReturnMsg( returnStr ); 

            haveData = true;
        }
        else
        {
            SDL_Delay(100);

            haveData = false;
        }
    }

我的问题是,如果 m_running 始终为 true。所以当我退出游戏时,线程仍在运行。会导致坠机吗?

I run my game on linux system of TV, when I exit game, the system will crash.

from the output log, I know my game has been quite, but system crash following.

the main function like below:

int main(int argc, char** argv)
{
 ......

 SDL_Quit();

 printf("Log: exit end. \n);// it's printed on console
 return 0;
}

I can find the output log about Log: exit end. So the game has been exit right?

I found the game exit will only crash after create threads.

Here is the run function in thread below:

   while ( pThread->m_running )
    {
        string str;
        string cmdStr;

        if ( pThread->GetSendMsg(str, cmdStr) )
        {
            string returnStr = Connection::DealHttpSendMsg( str, cmdStr );

            pThread->AddReturnMsg( returnStr ); 

            haveData = true;
        }
        else
        {
            SDL_Delay(100);

            haveData = false;
        }
    }

My question is that if the m_running is alway true. so when I exit the game, the thread is still running. Will it cause the crash?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云仙小弟 2024-11-03 15:41:36

如果该线程尝试访问同时被主线程销毁的资源,则会发生这种情况。

如果您有一个不执行任何操作的工作线程,则仅退出应用程序不会使其崩溃。

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* run_me(void*)
{
    while (1) 
    { 
       printf("Sleeping..\n");
       sleep(1);
    }
}

int main()
{
    pthread_t my_thread;

    pthread_create(&my_thread, NULL, &run_me, NULL);
    sleep(2);

    return 0;
}

It will if that thread tries to access resources that are being simultaneously destroyed by the main thread.

Just quitting the app won't crash it if you have a worker thread that does nothing.

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* run_me(void*)
{
    while (1) 
    { 
       printf("Sleeping..\n");
       sleep(1);
    }
}

int main()
{
    pthread_t my_thread;

    pthread_create(&my_thread, NULL, &run_me, NULL);
    sleep(2);

    return 0;
}
水溶 2024-11-03 15:41:36

return 0; 仅终止主线程。尝试使用 exit(0) 代替。

return 0; terminates only the main thread. Try to use exit(0) instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文