- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个小程序 ( here ),其中 main()
向所有工作线程发送相同的 msg
并且工作线程简单地打印消息
。
我想我完全遵循了this教程,来自官方指南。
我通过 void 指针将 0MQ context
传递给线程,然后将其转换回 zmq::context_t *
。但我仍然遇到了段错误。以下是 GDB 中 coredump 的信息:
Core was generated by `./test 1'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 zmq::ctx_t::check_tag (this=this@entry=0xabadcafe) at src/ctx.cpp:89
89 src/ctx.cpp: No such file or directory.
[Current thread is 1 (Thread 0x7fcdaae3f700 (LWP 1428))]
(gdb) bt
#0 zmq::ctx_t::check_tag (this=this@entry=0xabadcafe) at src/ctx.cpp:89
#1 0x00007fcdad17c275 in zmq_socket (ctx_=0xabadcafe, type_=7) at src/zmq.cpp:245
#2 0x0000000000402da1 in zmq::socket_t::init (this=0x7fcdaae3edf0, context_=..., type_=7) at /usr/include/zmq.hpp:649
#3 0x0000000000402ac3 in zmq::socket_t::socket_t (this=0x7fcdaae3edf0, context_=..., type_=7) at /usr/include/zmq.hpp:463
#4 0x0000000000401f18 in task1 (arg=0x170ac20) at test.cpp:21
#5 0x00000000004050fe in std::_Bind_simple<void (*(void*))(void*)>::_M_invoke<0ul>(std::_Index_tuple<0ul>) (this=0x170e0d8)
at /usr/include/c++/5/functional:1531
#6 0x0000000000405008 in std::_Bind_simple<void (*(void*))(void*)>::operator()() (this=0x170e0d8) at /usr/include/c++/5/functional:1520
#7 0x0000000000404f98 in std::thread::_Impl<std::_Bind_simple<void (*(void*))(void*)> >::_M_run() (this=0x170e0c0) at /usr/include/c++/5/thread:115
#8 0x00007fcdacc48c80 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9 0x00007fcdacf196ba in start_thread (arg=0x7fcdaae3f700) at pthread_create.c:333
#10 0x00007fcdac6b782d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb) quit
用 g++ -std=c++11 test.cpp -o test -lzmq -lpthread -g
编译的程序。
最佳答案
Context()
可以提供帮助: native API 推荐这种做法用于纯 inproc://
基于传输类的多线程用法:
The
zmq_init()
function initialises a ØMQ context.The
io_threads
argument specifies the size of the ØMQ thread pool to handle I/O operations. If your application is using only the inproc transport for messaging you may set this to zero, otherwise set it to at least one.Thread safety
A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller.
This function is deprecated by zmq_ctx_new(3).
最近的 { API/c++ wrapper } 将此步骤(最初在 { v2.1.11 API/c++ wrapper } 中通过 Context( NUM_io_threads )
在实例化时可用)移动到 { v4. 2.2 } 通过设置调用在实例化后(但套接字关联前)状态拆分过程zmq_ctx_set( *ctx, ZMQ_IO_THREADS, 0 )
/p>
int main( int argc, char* argv[] )
{
int worker_num;
if ( argc != 2 ) { cout << "1 parameter pls" << endl; exit(1); } // EXIT[1]
try
{
if ( !has_only_digits( string( argv[1] ) ) ) { cout << "digit pls" << endl; exit(1); } // EXIT[2]
worker_num = stoi( string( argv[1] ) );
}
catch ( exception e ) { cout << "exception while processing parameters" << endl; exit(1); } // EXIT[3]
// _______________________________________ // ZeroMQ inproc use-case W/O IO-thread
zmq::context_t context( 0 ); //
// _______________________________________ //
zmq::socket_t distask_socket( context, ZMQ_PUSH );
distask_socket.bind( "inproc://task_publisher" );
vector<thread> pool;
for ( int i = 0; i < worker_num; i++ )
{
cout << "main() : creating thread, " << i << endl;
pool.push_back( thread( task1,
(void *) &context
)
);
}
for ( int i = 0; i < worker_num; i++ )
{
zmq::message_t msg( 6 );
memcpy( (void *) msg.data(), "World", 6 );
distask_socket.send( msg );
}
for ( auto &t : pool )
t.join();
exit(0);
}
值得压榨最后一点性能并消除延迟源。
关于c++ - 0MQ : on passing a context to a pool of threads a Segmentation fault was thrown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44175460/
我正在尝试加载外部 SVG 并将其附加到 Electron 项目中的现有 SVG。 d3.xml 方法对我不起作用,所以我正在查看 d3.symbols ,希望如果我提供路径数据(来自 fs.read
我正在编写一个 Web 应用程序,使用 Go 作为后端。我正在使用这个 GraphQL 库 (link)和 Echo Web 框架 (link) .问题在于 graphql-go 库在 Go 中使用了
有没有办法改造 gin.Context至 context.Context在围棋?构建 Go 微服务应该使用什么? 最佳答案 标准库的 context.Context type 是一个接口(interf
如果我能够像这样注册一个接收器: LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new Inte
如果我有 appengine.Context 而不是 ,我不知道如何调用 cloud.WithContext 和 google.DefaultClient >上下文。上下文。 有(旧的)“appeng
有什么区别- AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SER
我刚读了这篇文章:Build You Own Web Framework In Go为了在处理程序之间共享值,我选择了 context.Context我通过以下方式使用它在处理程序和中间件之间共享值:
在 Visual Studio Code 中,我对 3 个“上下文”菜单项感到非常困惑:Run Tests in Context和 Debug Tests in Context和 Run .NET C
我正在使用带有 和 @Autowired 的 Spring 2.5.6 版本。 虽然我在调度程序上下文中使用 SimpleUrlHandlerMapping ,但一切正常 - Autowiring 工
我使用的是 Context.registerReceiver()、Context.sendBroadcast(Intent) 和 Context.unregisterReceiver() 但是当我看到
问题在于以下错误, [错误] 在 scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4580)[错误] 在 scal
最近我正在尝试使用 SoundPool 在我的应用程序中播放一些简单的音效 但不幸的是它在 AVD 中不起作用并且应用程序崩溃 “上下文”到底是什么意思? 完全不懂 提前致谢 最佳答案 任何上下文都允
我正在使用上下文建议器,我想知道我们是否可以设置用于建议的上下文范围,而不是使用所有上下文。 目前查询需要匹配所有上下文。我们能否在上下文中添加“或”运算和/或指定用于特定查询的上下文? 以here为
我被一个使用这种方法的函数卡住了。所以我知道如何使用 expressionValue(with:context:) 函数,但上下文如何参与对我来说仍然是不透明的。也许有人有简单的例子? try tra
我正在尝试在上下文管理器中更改我的 python 程序中的目录。使用 invoke.context.Context 似乎是正确的方法,从 Fabric 文档中获取并且使用常规 with os.chdi
我最近开始使用 Android Studio 处理我的 Android 项目。我注意到在 IDE 的右下角,有文本 Context: .好奇心打败了我,所以现在我正在网上搜索更多信息。我还没有找到任
假设我有这些功能: func A(ctx context.Context) { // A takes some time to process } func B(ctx context.Con
所以,我有一个 context.Context( https://golang.org/pkg/context/ ) 变量,有没有办法列出这个变量包含的所有键? 最佳答案 可以使用不安全反射列出 co
我正在尝试找出传播 context.Context 的正确方法用于在使用 Gin 时使用 OpenTelemetry 进行跟踪。 我目前有一个 gin调用函数并传递 *gin.Context 的处理程
我们可以使用 Remove["context`*"] 删除特定上下文中的所有符号。 .但是是否可以删除 "context`"自己从系统中删除,以便它不再在 Contexts[] 中列出? 最佳答案 据
我是一名优秀的程序员,十分优秀!