一、背景
上篇文章《c语言数据结构实现-数组队列/环形队列》讲述了数组队列的原理与实现,本文编写一个双线程进行速度测试
二、相关知识
多线程编程接口:
1) 创建线程 pthread_create 函数
SYNOPSIS
#include int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
Compile and link with -pthread.
DESCRIPTION:
The pthread_create() function starts a new thread in the calling process. The new thread starts execution by invoking start_routine(); arg is passed as the sole argument of start_routine().
RETURN VALUE:
On success, pthread_create() returns 0; on error, it returns an error number, and the contents of *thread are undefined.
2) 设置线程属性 pthread_attr_setdetachstate
SYNOPSIS
#include int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
Compile and link with -pthread.
DESCRIPTION
The pthread_attr_setdetachstate() function sets the detach state attribute of the thread attributes object referred to by attr to the value specified in detachstate. The detach state attribute determines whether a thread created using the thread attributes object attr will be created in a joinable or a detached state.
RETURN VALUE
On success, these functions return 0; on error, they return a nonzero error