tha_notify_acquire_lock(id)() |
在程序尝试获取用户定义的锁之前立即插入。 |
tha_notify_lock_acquired(id)() |
在成功获取用户定义的锁之后立即插入。 |
tha_notify_writelock_acquired(id)() |
在写入模式下成功获取用户定义的读写锁之后立即插入。 |
tha_notify_readlock_acquired(id)() |
在读取模式下成功获取用户定义的读写锁之后立即插入。 |
tha_notify_lock_released(id)() |
在成功释放用户定义的锁(包括读写锁)之后立即插入。 |
tha_notify_sync_post_begin(id)() |
在执行用户定义的后同步之前立即插入。 |
tha_notify_sync_post_end(id)() |
在执行用户定义的后同步之后立即插入。 |
tha_notify_sync_wait_begin(id)() |
执行用户定义的等待同步之前立即插入。 |
tha_notify_sync_wait_end(id)() |
执行用户定义的等待同步之后立即插入。 |
提供了 API 的 C/C++ 版本和 Fortran 版本。每个 API 调用都采用单个参数 id,其值应该唯一标识同步对象。
在 API 的 C/C++ 版本中,参数类型为 uintptr_t,在 32 位模式下其长度为 4 字节,在 64 位模式下其长度为 8 字节。调用任何 API 时,都需要将 #include <tha_interface.h> 添加到 C/C++ 源文件中。
在 API 的 Fortran 版本中,参数类型为整型 tha_sobj_kind,在 32 位和 64 位模式下其长度都为 8 字节。调用任何 API 时,都需要将 "tha_finterface.h" 添加到 Fortran 源文件中。要唯一标识同步对象,每个不同同步对象的参数 ID 应具有不同的值。一种执行此操作的方法是将同步对象的地址值用作 ID。以下代码示例说明如何使用 API 避免误报的数据争用:
# include <tha_interface.h> ... /* Initially, the ready_flag value is zero */ ... /* Thread 1: Producer */ 100 data = ... 101 pthread_mutex_lock (&mutex); tha_notify_sync_post_begin ((uintptr_t) &ready_flag); 102 ready_flag = 1; tha_notify_sync_post_end ((uintptr_t) &ready_flag); 103 pthread_cond_signal (&cond); 104 pthread_mutex_unlock (&mutex); /* Thread 2: Consumer */ 200 pthread_mutex_lock (&mutex); tha_notify_sync_wait_begin ((uintptr_t) &ready_flag); 201 while (!ready_flag) { 202 pthread_cond_wait (&cond, &mutex); 203 } tha_notify_sync_wait_end ((uintptr_t) &ready_flag); 204 pthread_mutex_unlock (&mutex); 205 ... = data;
有关用户 API 的更多信息,请参见 libtha.3 手册页。