What kind of story does the source code tell

Marc 2022-03-14 14:12:21

After thinking about it, the plot of the source code can be roughly represented by the following code

#include

#include

#include

#include

#include

#include

using namespace std;

struct World;

struct Person

{

std::vector m_Memories;

std::string m_Name;

World *m_pWorld = nullptr;

Person(const std::string &name)

: m_Name(name)

{}

};

int g_TrainThreadInited = 0;

int g_TrainThreadCrashed = 0;

int g_TryTimes = 0;

Person g_p1("Stevens"), g_p2("Sean");

struct World

{

Person *m_pMainCharacter = nullptr;

World(Person *character)

: m_pMainCharacter(character)

{}

void SadStory()

{

cout << "Boom !" << endl;

}

void HappyStory()

{

cout << "Mua !" << endl;

}

};

void TrainThread(World *pWorld)

{

try

{

if (g_TryTimes <8)

{

pWorld->SadStory();

++g_TryTimes;

throw std::exception("Boom !");

}

else

pWorld->HappyStory();

}

catch (std::exception &e)

{

pWorld->m_pMainCharacter->m_Memories.push_back(e.what());

g_TrainThreadCrashed = 1;

}

}

int main()

{

std::shared_ptr threadptr;

for (;;)

{

if (!g_TrainThreadInited || g_TrainThreadCrashed)

{

World w(&g_p2);

g_p1.m_pWorld = &w;

w.m_pMainCharacter = &g_p1;

threadptr.reset(new thread (TrainThread, &w));

threadptr->detach();

if (!g_TrainThreadInited)

g_TrainThreadInited = 1;

if (g_TrainThreadCrashed)

g_TrainThreadCrashed = 0;

}

}

return 0;

}

View more about Source Code reviews

Extended Reading
  • Candelario 2022-03-25 09:01:05

    In some, you exist, but I do not exist; in others, I exist, but you do not exist; in others, you and I both exist. Time intersects forever, until the innumerable future. In one of these intersections, I am your enemy.

  • Paris 2022-04-24 07:01:02

    The subject matter is quite novel, and I feel very refreshed when I watch it, but it is still a popcorn film. After reading it, I have no impression

Source Code quotes

  • Colleen Goodwin: If you find the bomber, this second attack - the real attack, we think - can be prevented. We have very little time left. Out here, the clocks only move in one direction.

  • Derek Frost: The world is Hell. We have a chance to start over in the rubble. But first, there has to be rubble.