如何使openmp线程睡眠 [英] How to make openmp thread sleep

查看:99
本文介绍了如何使openmp线程睡眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开展一个用OOP设计机场的项目。我正在使用c ++。我的程序中有一个主要的Airport对象,它有RequestLanding()函数,用于分配飞机可以降落的跑道号。此功能返回两个枚举中的一个 - 保持或继续以指示飞机是否应着陆。



从外面有许多飞机物体可以进行着陆请求。我用于循环飞机物体的总数。我正在使用OpenMp进行并行循环。当RequestLanding()函数返回状态Hold然后再试一次时,我想做一个openmp睡眠线程3秒钟。



有没有办法做到这一点?有人可以提供一个简单的例子。在此先感谢。



我尝试过:



i还没有尝试了什么。找不到信息

I am currently working on a project to design Airport with OOP. I am using c++. I have a main Airport object in my program which has RequestLanding() function which assigns the runway number on which plane can land. This function returns one of the two enums- Hold or Proceed to indicate whether plane should land or not.

From the outside there are many airplane objects which makes the landing request. I am using for loop for the total number of airplane objects. I am using OpenMp for parallel loop. I wanted to make a thread of openmp sleep for 3 seconds when the RequestLanding() function returns the state Hold and then try again.

Is there a way to do this ? Can someone provide a simple example. Thanks in advance.

What I have tried:

i have not tried anything. could not find the information

推荐答案

我会解决这个问题,而不是一些等待函数,而是一个信号量解决方案。信号量是允许一些指定访问的资源,因此最适合您的问题。



学习信号量是Microsoft 以及一些更深入的见解



此链接可以帮助您找到堆栈溢出
I would solve this problem NOT with some waiting function, but a semaphore solution. Semaphore are resources which allowing some designated access and so fitting best for your probelm.

For learning on semaphores is a short explanation from Microsoft and also some deeper insights.

This link may help you in finding the final solution on Stack overflow.


这篇关于如何使openmp线程睡眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆