当前位置:网站首页>B_ QuRT_ User_ Guide(19)

B_ QuRT_ User_ Guide(19)

2022-06-11 03:00:00 weixin_ thirty-eight million four hundred and ninety-eight thou

12 barrier

Threads use barriers to synchronize their execution at specific points in the program .

When a barrier is initialized , It is assigned a user specified integer value . This value indicates the number of threads to synchronize on the barrier .

When a thread waits on a barrier , It will hang on the barrier :

  • If the total number of threads waiting for the barrier is less than the allocated value of the barrier , No other operation will occur .
  • If the total number of threads waiting for the barrier is equal to the allocated value of the barrier , Then wake up all threads currently waiting for the barrier , Allow them to cross the barrier to perform .

After its waiting thread is awakened , The barrier will reset automatically , And can be used again in the program , Without re initializing .
A barrier is a shared object that supports the following operations :

  • qurt_barrier_destroy()
  • qurt_barrier_init()
  • qurt_barrier_wait()
  • Data Types

12.1 qurt_barrier_destroy()

12.1.1 Function document

12.1.1.1 int qurt_barrier_destroy ( qurt_barrier_t ∗ barrier )

Break the designated barrier .

 Be careful : The barrier must be destroyed when it is no longer in use .   Failure to do so will result in  QuRT  A resource leak in the kernel .

Do not break the barrier while it is still in use . If this happens , be QuRT The behavior of is undefined .

Related data types
qurt_barrier_t

Parameters

inbarrier Pointer to the barrier object to be destroyed .

Return value
Unused integer values .

Dependency relationship
None.

12.2 qurt_barrier_init()

12.2.1 Function document

12.2.1.1 int qurt_barrier_init ( qurt_barrier_t ∗ barrier, unsigned int threads_total )

Initialize the barrier object .

Related data types
qurt_barrier_t

Parameters

outbarrier Pointer to the barrier object to initialize .
inthreads_total The total number of threads to synchronize on the barrier .

Return value
Unused integer values .

Dependency relationship
None.

12.3 qurt_barrier_wait()

12.3.1 Function document

12.3.1.1 int qurt_barrier_wait ( qurt_barrier_t ∗ barrier )

Waiting on the barrier .
Suspend the current thread on the specified barrier .
The return value of the function indicates whether the thread is the last thread synchronized on the barrier . When a thread waits on a barrier , It will hang on the barrier :

  • If the total number of threads waiting for the barrier is less than the allocated barrier value , No other operation will occur .
  • If the total number of threads waiting for the barrier is equal to the allocated barrier value , Then wake up all threads currently waiting for the barrier , Allow them to cross the barrier to perform .
 Be careful : After its waiting thread is awakened , The barrier will reset automatically , It can be used again in the program , No need to reinitialize .

Related data types
qurt_barrier_t

Parameters

inbarrier Pointer to the barrier object to wait for .

Return value
QURT_BARRIER_OTHER – Current thread wakes up from barrier .
QURT_BARRIER_SERIAL_THREAD – The current thread is the last caller of the barrier .

Dependency relationship
None.

12.4 data type

This section describes the data types of barrier Services .

  • Obstacles in QuRT Said to qurt_barrier_t Object of type .

12.4.1 Define documents

12.4.1.1 #define QURT_BARRIER_SERIAL_THREAD 1

Serial threads .

12.4.1.2 #define QURT_BARRIER_OTHER 0

other .

12.4.2 Data structure document

12.4.2.1 union qurt_barrier_t

QuRT Barrier type .

原网站

版权声明
本文为[weixin_ thirty-eight million four hundred and ninety-eight thou]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110238526848.html