<tfoot id='kox71'></tfoot>
        <bdo id='kox71'></bdo><ul id='kox71'></ul>
    1. <legend id='kox71'><style id='kox71'><dir id='kox71'><q id='kox71'></q></dir></style></legend>
      <i id='kox71'><tr id='kox71'><dt id='kox71'><q id='kox71'><span id='kox71'><b id='kox71'><form id='kox71'><ins id='kox71'></ins><ul id='kox71'></ul><sub id='kox71'></sub></form><legend id='kox71'></legend><bdo id='kox71'><pre id='kox71'><center id='kox71'></center></pre></bdo></b><th id='kox71'></th></span></q></dt></tr></i><div id='kox71'><tfoot id='kox71'></tfoot><dl id='kox71'><fieldset id='kox71'></fieldset></dl></div>

      1. <small id='kox71'></small><noframes id='kox71'>

        跨平台等价于windows事件

        时间:2023-07-20

        • <tfoot id='c1l0b'></tfoot>

            <tbody id='c1l0b'></tbody>
            <legend id='c1l0b'><style id='c1l0b'><dir id='c1l0b'><q id='c1l0b'></q></dir></style></legend>

            <small id='c1l0b'></small><noframes id='c1l0b'>

            • <bdo id='c1l0b'></bdo><ul id='c1l0b'></ul>

                <i id='c1l0b'><tr id='c1l0b'><dt id='c1l0b'><q id='c1l0b'><span id='c1l0b'><b id='c1l0b'><form id='c1l0b'><ins id='c1l0b'></ins><ul id='c1l0b'></ul><sub id='c1l0b'></sub></form><legend id='c1l0b'></legend><bdo id='c1l0b'><pre id='c1l0b'><center id='c1l0b'></center></pre></bdo></b><th id='c1l0b'></th></span></q></dt></tr></i><div id='c1l0b'><tfoot id='c1l0b'></tfoot><dl id='c1l0b'><fieldset id='c1l0b'></fieldset></dl></div>

                1. 本文介绍了跨平台等价于windows事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将一些 Windows 代码移植到 Linux,理想情况下是通过独立于平台的库(例如 boost),但是我不确定如何移植这部分事件代码.

                  I'm trying to port some Windows code to Linux, ideally through platform-independent libraries (eg boost), however I'm not sure how to port this bit of event code.

                  这段代码涉及两个线程(我们称它们为 A 和 B).A 想做一些只有 B 才能做的事情,所以它向 B 发送一条消息,然后等待 B 说它完成了.在 Windows 中,这看起来像:

                  The bit of code involves two threads (lets call them A and B). A wants to do something that only B can, so it sends B a message, then waits for B to say its done. In windows this looks something like:

                  void foo();//thread a calls this
                  void bar(HANDLE evt);
                  
                  void foo()
                  {
                      HANDLE evt = CreateEvent(0,FALSE,FALSE,0);
                      bCall(boost::bind(&bar, evt));
                      WaitForSingleObject(evt,INFINITE);
                      CloseHandle(evt);
                  }
                  void bar(HANDLE evt)
                  {
                      doSomething();
                      SetEvent(evt);
                  }
                  

                  我查看了 boost::thread 库,但它似乎没有执行此操作的任何东西,我可以看到的关闭是 boost::condition_variable,但它似乎是与互斥锁结合使用的意思,即不是这里的情况.

                  I looked at the boost::thread library, but it didnt seem to have anything that does this, the closes I could see was the boost::condition_variable, but it appears that is means in conjunction with a mutex, which is not the case here.

                  推荐答案

                  我认为一个好的、跨平台的等价于 win32 事件的是 boost::condition,因此您的代码可能如下所示:

                  I think a good, cross-platform equivalent to win32 events is boost::condition, so your code could look something like this:

                  void foo()
                  {
                      boost::mutex mtxWait; 
                      boost::condition cndSignal;
                  
                      bCall(boost::bind(&bar, mtxWait, cndSignal));
                  
                      boost::mutex::scoped_lock mtxWaitLock(mtxWait);
                      cndSignal.wait(mtxWait); // you could also use cndSignal.timed_wait() here
                  }
                  
                  void bar(boost::mutex& mtxWait, boost::condition& cndSignal)
                  {
                      doSomething();
                      cndSignal.notify_one();
                  }
                  

                  这篇关于跨平台等价于windows事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:CMake 无法找到 BOOST 库 下一篇:理解 boost::disjoint_sets

                  相关文章

                    <small id='dzsTm'></small><noframes id='dzsTm'>

                    <tfoot id='dzsTm'></tfoot>
                    • <bdo id='dzsTm'></bdo><ul id='dzsTm'></ul>
                    <i id='dzsTm'><tr id='dzsTm'><dt id='dzsTm'><q id='dzsTm'><span id='dzsTm'><b id='dzsTm'><form id='dzsTm'><ins id='dzsTm'></ins><ul id='dzsTm'></ul><sub id='dzsTm'></sub></form><legend id='dzsTm'></legend><bdo id='dzsTm'><pre id='dzsTm'><center id='dzsTm'></center></pre></bdo></b><th id='dzsTm'></th></span></q></dt></tr></i><div id='dzsTm'><tfoot id='dzsTm'></tfoot><dl id='dzsTm'><fieldset id='dzsTm'></fieldset></dl></div>
                      <legend id='dzsTm'><style id='dzsTm'><dir id='dzsTm'><q id='dzsTm'></q></dir></style></legend>