请问linux下线程和一个定时器之间同步的问题!
#include <stdio.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
//#define BUFFER_SIZE 16
#define BUFFER_SIZE 2
#define OVER ( - 1)
struct prodcons
{
int buffer[BUFFER_SIZE];
pthread_mutex_t lock;
int readpos, writepos;
pthread_cond_t notempty;
pthread_cond_t notfull;
};
struct prodcons buffer;
void init(struct prodcons *b)
{
pthread_mutex_init(&b->lock, NULL);
pthread_cond_init(&b->notempty, NULL);
pthread_cond_init(&b->notfull, NULL);
b->readpos = 0;
b->writepos = 0;
}
void put(struct prodcons *b, int data)
{
pthread_mutex_lock(&b->lock);
if ((b->writepos + 1) % BUFFER_SIZE == b->readpos)
{
pthread_cond_wait(&b->notfull, &b->lock);
}
b->buffer[b->writepos] = data;
b->writepos++;
if (b->writepos >= BUFFER_SIZE)
b->writepos =
相关问答:
写了个测试程序如下
struct hostent *hp;
char AlarmDevIP[20];
int x2;
hp = gethostbyname("www.google.com");
if (hp)
{
......
由于我才刚刚接触socket编程,自己写了一个简单程序,但就是在运行的时候出现段错误,无法解决,现在我把源代码贴出来,请各位大虾指正一下!谢谢!
#include<stdio.h>
#include<stdlib.h>
#include& ......
咨询QQ:269562808
bzip2recover
功能说明:用来修复损坏的.bz2文件。
语法:bzip2recover[.bz2压缩文件]
补充说明:bzip2是以区块的方式来压缩文件,每个区块视为独立的单位。因此,当某一区
块损坏时,便可利 ......
各位老师好:小弟有一点问题 琢磨了好久想请教大师们:
我在安装mysql的时候 安装到
./configure \
--prefix=/usr/local/mysql \
--with-extra-charsets=all
这步的时候出现:
configure: unknown option --p ......
如题。请指教,多谢!
http://www.chinaunix.net/jh/50/1394871.html
虽然你给的网址不能解决我的问题,还是要谢谢你!
我采用IPSec工具是strongSwan。
虽然你给的网址不能解决我的问题,还是要谢谢你!&nbs ......