首页 \ 问答 \ `pthread_create`的`pthread_t *`参数需要多长时间才能存活?(How long does the `pthread_t*` argument to `pthread_create` need to survive?)

`pthread_create`的`pthread_t *`参数需要多长时间才能存活?(How long does the `pthread_t*` argument to `pthread_create` need to survive?)

pthread_create(3)的签名是:

   int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                      void *(*start_routine) (void *), void *arg);

pthread_t *thread参数的存储持续时间有哪些要求? pthread_create的手册页说:

在返回之前,成功调用pthread_create()会将新线程的ID存储在线程指向的缓冲区中;

但是不清楚它是否意味着它将值存储在那里以便调用者可以检查它,或者它是否使用该缓冲区来存储值(暗示缓冲区需要在子线程的整个生命周期内保持可用)。

同样, pthread_self说它返回

创建此线程的pthread_create(3)调用中*thread中返回的相同值。

但是不清楚它是否意味着它返回存储在*thread 的值或者等于 *thread返回的值

具体来说,我想知道这样的事情是否合法:

void make_thread(void) {
  pthread_t tid;
  return pthread_create(&tid, NULL, some_fn, NULL);
}

或者如果tid需要是malloc 。 当我把tid放在堆栈上时,我在与_Unwind_ForcedUnwind相关的valgrind中得到了一堆错误,这让我怀疑*thread需要在子线程的生命周期内保持有效。


The signature of pthread_create(3) is:

   int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                      void *(*start_routine) (void *), void *arg);

What are the requirements on the storage duration of the pthread_t *thread argument? The man page for pthread_create says:

Before returning, a successful call to pthread_create() stores the ID of the new thread in the buffer pointed to by thread;

But it's not clear if it means that it stores the value there so that the caller can examine it, or if it uses that buffer to store the value (implying that the buffer needs to stay usable for the whole lifetime of the child thread).

Similarly, pthread_self says it returns

the same value that is returned in *thread in the pthread_create(3) call that created this thread.

but it's not clear if it means that it returns the value stored in *thread or a value equal to what was returned in *thread.

Concretely, I'm wondering if it's legal to have something like:

void make_thread(void) {
  pthread_t tid;
  return pthread_create(&tid, NULL, some_fn, NULL);
}

or if tid needs to be malloc'd. When I put tid on the stack, I get a bunch of errors in valgrind related to _Unwind_ForcedUnwind, which makes me suspect that *thread needs to remain valid for the lifetime of the child thread.


原文:https://stackoverflow.com/questions/35928654
更新时间:2022-08-21 22:08

最满意答案

这是c#绑定的答案,我猜你正在使用java绑定,但它应该几乎相同。

首先,您应该使用此处的selenium-server-standalone-2.0b3.jar在远程selenium服务器上启动selenium服务器: http//code.google.com/p/selenium/downloads/list

你开始使用:

java -jar selenium-server-standalone-2.0b3.jar

在您的测试中,您使用RemoteWebDriver,如下所示:

var desiredCapabilities = DesiredCapabilities.Firefox();
var selenium = new RemoteWebDriver(new Uri("http://seleniumserver1:4444/wd/hub"), desiredCapabilities);

这应该确保您的测试脚本将所有webdriver命令发送到远程服务器。

Grid 2.0应该在selenium 2.0 beta 4中,这样可以更容易地使用两个selenium服务器。 (我猜你现在可以自己切换服务器网址)


This is an answer for the c# bindings, I guess you're using the java bindings but it should almost be the same.

First you should start the selenium server on the remote selenium server using the selenium-server-standalone-2.0b3.jar found here: http://code.google.com/p/selenium/downloads/list

You start it using:

java -jar selenium-server-standalone-2.0b3.jar

In your test you use the RemoteWebDriver like this:

var desiredCapabilities = DesiredCapabilities.Firefox();
var selenium = new RemoteWebDriver(new Uri("http://seleniumserver1:4444/wd/hub"), desiredCapabilities);

That should make sure your testscripts send all webdriver commands to the remote server.

Grid 2.0 should be in selenium 2.0 beta 4 making it easier to use both selenium servers. ( I guess now you could switch server urls by yourself )

相关问答

更多
  • 是的,您需要运行X服务器,因为Selenium需要运行浏览器,并且浏览器需要某种X服务器才能运行。 幸运的是,有许多类型的X服务器,其中之一是Xvfb又名X虚拟帧缓冲区,它执行内存中的所有操作,因此不需要屏幕。 维基百科也有一些很好的例子 。 关于headless , xvfb和selenium关键字,还有很多关于SO的问题。 做出明智的选择 ;) [编辑] : 这是一个很好的例子 。 Yes, you need to have X server running because Selenium requi ...
  • 你的意思是Selenium WebDriver? 呵呵.... 先决条件 :根据您的操作系统安装Python 安装以下命令 pip install -U selenium 并在你的代码中使用这个模块 from selenium import webdriver 您还可以根据需要使用许多以下内容 from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium ...
  • 您可以从命令行运行ide测试: http : //www.seleniumhq.org/docs/05_selenium_rc.jsp#running-selenium-server 使用htmlSuite选项: https ://wiki.mozilla.org/Running_IDE_scripts_with_Selenium_RC 然后你可以使用cron作业从命令行运行它,或者你可以使用Jenkins插件: https : //wiki.jenkins-ci.org/display/JENKINS/S ...
  • 解决方案:AutoITx.jar。 在selenium中导入jar并直接在selenium web驱动中使用autoit脚本。 The solution: AutoITx.jar. import the jar in selenium and directly use the autoit script in selenium web driver.
  • 唯一的区别是你的GCE实例没有显示,这对你的浏览器来说是个问题。 为了解决这个问题,你需要使用“Virtual Framebuffer”来运行Selenium。 这基本上是一个“假显示”。 以下是在Ubuntu中设置虚拟帧缓冲区的方法: sudo apt-get install xvfb sudo Xvfb :10 -ac 然后,在开始你的硒脚本之前,运行: export DISPLAY=:10 The only difference is that your GCE instance doesn't ...
  • IDE生成的文件可以与服务器一起运行。 java -jar“[Selenium服务器.jar文件的路径]”-htmlSuite“* [浏览器,请参阅此处的列表 ]”“[浏览器将在启动时导航到的URL]”“[HTML测试套件文件的路径在IDE中制作“”[服务器将写入的HTML结果文件的路径]“ 本页讨论了这个进一步阅读的过程 。 The files generated by the IDE can be run with the server. java -jar "[path to the Selenium ...
  • 因此,我们最终通过Atlassian Bamboo使用ANT脚本来完成这项工作。 我们正在部署Bamboo以进行其他维护并构建问题。 然而,从我所做的研究来看,看起来Jenkins-CI(以前的Hudson-CI)是一个可以做同样事情或非常相似的自由选项。 So we ended up using an ANT script through Atlassian Bamboo to get this job done. We were deploying Bamboo for other maintenanc ...
  • 由于您需要登录远程计算机,因此AFAICT无法做到这一点“没有ssh”。 但是, ssh接受一个在远程机器上执行的命令(而不是启动的shell)。 因此,如果您可以将脚本保存在远程机器上,例如〜/ script.sh,则可以在不启动交互式shell的情况下执行它 $ ssh remote_machine ~/script.sh 一个脚本终止连接将被自动关闭(如果你没有故意配置)。 Since you need to log into the remote machine there is AFAICT n ...
  • 一个想法。 您可以创建一个结合Jenkins / Selenium / Amazon的基础设施。 以下是来自另一篇文章的解决方案。 你可以用网格来完成。 首先,您需要创建一个带有EC2 ubuntu 14.04 AMI的Selenium hub,无需UI,并将其作为jenkins slave连接到Jenkins master。 或者直接成为主人。 你想要什么。 只有命令行。 单独下载Selenium Server。 (下载版本时要小心。如果下载Selenium3Beta,事情可能会发生变化)。 在这里你可以 ...
  • 这是c#绑定的答案,我猜你正在使用java绑定,但它应该几乎相同。 首先,您应该使用此处的selenium-server-standalone-2.0b3.jar在远程selenium服务器上启动selenium服务器: http : //code.google.com/p/selenium/downloads/list 你开始使用: java -jar selenium-server-standalone-2.0b3.jar 在您的测试中,您使用RemoteWebDriver,如下所示: var des ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。