获取内容资料
Linux运维

黑马linux学习笔记

#include #include #include #include #include #include #include // 节点结构typedef struct node{int data;struct node* next;}Node;// 永远指向链表头部的指针Node* head = NULL;// 线程同步 – 互斥锁pthread_mutex_t mutex;// 阻塞线程 – 条件变量类型的变量pthread_cond_t cond;// 生产者void* producer(void* arg){while(1){// 创建一个链表的节点Node* pnew = (Node*)malloc(sizeof(Node));// 节点的初始化pnew->data = rand % 1000; // 0-999// 使用互斥锁保护共享数据pthread_mutex_lock(&mutex);// 指针域pnew->next = head;head = pnew;printf(“====== produce: %lu, %d\n”, pthread_self, pnew->data);pthread_mutex_unlock(&mutex);// 通知阻塞的消费者线程,解除阻塞pthread_cond_signal(&cond);sleep(rand % 3);}return NULL;}void* customer(void* arg){while(1){pthread_mutex_lock(&mutex);// 判断链表是否为空if(head == NULL){// 线程阻塞// 该函数会对互斥锁解锁pthread_cond_wait(&cond, &mutex);// 解除阻塞之后,对互斥锁做加锁操作}// 链表不为空 – 删掉一个节点 – 删除头结点Node* pdel = head;head = head->next;printf(“– customer: %lu, %d\n”, pthread_self, pdel->data);free(pdel);pthread_mutex_unlock(&mutex);}return NULL;}int main(int argc, const char* argv){pthread_t p1, p2;// initpthread_mutex_init(&mutex, NULL);pthread_cond_init(&cond, NULL);// 创建生产者线程pthread_create(&p1, NULL, producer, NULL);// 创建消费者线程pthread_create(&p2, NULL, customer, NULL);// 阻塞回收子线程pthread_join(p1, NULL);pthread_join(p2, NULL);pthread_mutex_destroy(&mutex);pthread_cond_destroy(&cond);return 0;}九十. 使用条件变量,实现生产者消费者模型。

黑马linux学习笔记

#include #include #include #include #include #include #include // 全局变量int number;pthread_rwlock_t rwlock;void* write_func(void* arg){while(1){//加写锁pthread_rwlock_wrlock(&rwlock);number++;printf(“+++ write number: %d\n”, number);//解锁pthread_rwlock_unlock(&rwlock);usleep(1000);}return NULL;}void* read_func(void* arg){while(1){pthread_rwlock_rdlock(&rwlock);printf(” read number: %d\n”, number);pthread_rwlock_unlock(&rwlock);usleep(500);}return NULL;}int main(int argc, const char* argv){pthread_t thid[8];pthread_rwlock_init(&rwlock, NULL);// 创建3个写线程for(int i=0; i<3; ++i){pthread_create(&thid[i], NULL, write_func, NULL);}//创建5个读线程for(int i=3; i<8; ++i){pthread_create(&thid[i], NULL, read_func, NULL);}// 回收子线程的pcbfor(int i=0; i<8; ++i){pthread_join(thid[i], NULL);}//释放读写锁资源pthread_rwlock_destroy(&rwlock);return 0;}八十七. 条件变量的使用思路。

在Linux运维学习的过程中,重要的是愿意持续学习,以及有持之以恒的决心。了解了Linux运维的发展方向之后,选择Linux来学习并进入it互联网行业也是一个不错的选择。

阶段:中级进阶中级进阶需要在充分了解linux原理和基础知识之后,对上层的应用和服务进行深入学习,其中说到服务肯定涉及到网络的相关知识,是需要花时间学习的。

什么是云计算?为什么要学习云计算?想更多地了解Linux云计算学习?请关注老男孩教育官网。也可咨询在线客服,领取试听学习视频及Linux云计算运维教学大纲。

黑马头条推荐系统属于机器学习与深度学习推荐应用项目,类似今日头条、掘金等推荐。用户可以通过黑马头条APP获取个性化推荐技术文章的效果。黑马头条推荐建立在海量用户与文章之上,主要在Feed流推荐、相关推荐、猜你喜欢应用场景。黑马头条使用 Lambda架构整合实时计算和离线计算, 借助分布式环境提升计算能力,通过ALS、LR、Wide&Deep 等机器 学习与深度学习、推荐算法进行智能推荐。提高了优秀文章的点击率,增加热门文章和新文章的推荐占比,达到千人千面的用户推荐效果。

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注