首页 > 解决方案 > C++ 程序在 ODE 上超时

问题描述

我编写了一个在 coliru 和ideone上都超时的程序。

程序在多线程环境中调用call_once (): -- EDIT -- :源代码添加

** 
    call_once_xcp.cpp

    Demonstrate that if the first call to the call_once() function
    is unsuccessful, it will invoke a subsequent functionality.

**/

#include <mutex>        /// once_flag, call_once()
#include <thread>       /// thread
#include <exception>        /// runtime_error
#include <iostream>     /// cout

using namespace std;

once_flag of;

/// declarations ...
void func_call_xcp();   /// will call func_xcp()
void func_xcp();    /// will throw
void func_call_OK();    /// will call func_OK()
void func_OK();     /// won't throw


int main()
{
   thread t1 {func_call_xcp};
   t1.join();

   thread t2 {func_call_OK};
   t2.join();

   thread t3 {func_call_OK};
   t3.join();
}


/// will call func_xcp()
void func_call_xcp()
{
   try
   {
      call_once(of, func_xcp);
   }
   catch (exception& e)
   {
      cout << "exception: " << e.what()
           << endl;
   }
}


/// will call func_OK()
void func_call_OK()
{
   call_once(of, func_OK);
}


void func_xcp()     /// will throw
{
   cout << "** func_xcp()" << endl;

   throw runtime_error 
       {"error in func_xcp()"};
}


void func_OK()      /// won't throw
{
   cout << "** func_OK()" << endl;
}


消息是:

Time limit exceeded #stdin #stdout 5s 4364KB 

有没有办法增加这些ODE(在线开发环境)或任何其他 ODE的时间限制?

标签: c++multithreadingide

解决方案


因此,如果问题是要找到可以运行此代码的在线 IDE,请尝试查看 Online GDB。似乎运行良好:

https://onlinegdb.com/rydvS9pTM

在 MSVC 2015 等本地主机上也可以正常运行。


推荐阅读