源程式:
#include
#include
#include
#include
#include
#define bufsize 4
#define number 8
int sum_of_number=0;
sem_t write_res_number;
sem_t read_res_number;
struct recycle_buffer
re_buf;
pthread_mutex_t buffer_mutex=pthread_mutex_initializer;
void *prod(void *arg)
return null;
}void *consumer(void *arg)
return null;
}int main()
{pthread_t pid,cid;
int i;
re_buf.head=0;
re_buf.tail=0;
for(i=0;i1。
procuder -1210569840 write 0.
procuder -1210569840 write 1.
consumer -1218962544 read 0.
procuder -1210569840 write 2.
consumer -1218962544 read 1.
consumer -1218962544 read 2.
procuder -1210569840 write 3.
procuder -1210569840 write 4.
procuder -1210569840 write 5.
procuder -1210569840 write 6.
consumer -1218962544 read 3.
consumer -1218962544 read 4.
consumer -1218962544 read 5.
consumer -1218962544 read 6.
procuder -1210569840 write 7.
procuder -1210569840 write 8.
consumer -1218962544 read 7.
consumer -1218962544 read 8.
the sum of number is 3685
672。
procuder -1209984112 write 0.
procuder -1209984112 write 1.
procuder -1209984112 write 2.
procuder -1209984112 write 3.
consumer -1218376816 read 0.
consumer -1218376816 read 1.
consumer -1218376816 read 2.
consumer -1218376816 read 3.
procuder -1209984112 write 4.
procuder -1209984112 write 5.
procuder -1209984112 write 6.
procuder -1209984112 write 7.
consumer -1218376816 read 4.
consumer -1218376816 read 5.
consumer -1218376816 read 6.
consumer -1218376816 read 7.
procuder -1209984112 write 8.
consumer -1218376816 read 8.
the sum of number is 3685
67
執行緒的生產者消費者
新建乙個產品person package cn.lucky.producer author lucky public class person public synchronized void pop 新建生產者 package cn.lucky.producer author lucky publ...
生產者消費者執行緒
include include include includeusing namespace std typedef int semaphore 訊號量是一種特殊的整型變數 const int size of buffer 5 緩衝區長度 const unsigned short producers...
生產者消費者執行緒
該簡單生產者 消費者執行緒,屬於本人學習過程中的一段練習 如有不足,請指點 package com.lanqiao.demo3 author 大廣子 類說明 簡單的生產者,消費者執行緒 public class threadptcs catch interruptedexception e 退出 s...