#include<stdio.h>#include<pthread.h>#include<string.h>#include<unistd.h>FILE *fp;//线程函数1void*wrfunc1(void*arg);//线程函数2void*wrfunc2(void*arg);//线程函数3void*wrfunc3(void*arg);//静态创建互斥锁pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;intmain(int argc,char*argv[]){//三个线程idpthread_t tid1;pthread_t tid2;pthread_t tid3;//三个线程参数int arg1 =1;int arg2 =2;int arg3 =3;//三个线程返回值void*ret1;void*ret2;void*ret3;if((fp =fopen("test.txt","a+"))==NULL){perror("fopen");}//创建三个线程pthread_create(&tid1,NULL, wrfunc1,&arg1);sleep(2);pthread_create(&tid2,NULL, wrfunc2,&arg2);sleep(2);pthread_create(&tid3,NULL, wrfunc3,&arg3);sleep(2);//延长休眠时间,保证三个线程都有机会执行sleep(100);//取消线程pthread_cancel(tid1);pthread_cancel(tid2);pthread_cancel(tid3);//回收线程pthread_join(tid1,&ret1);pthread_join(tid2,&ret2);pthread_join(tid3,&ret3);return0;}void*wrfunc1(void*arg){char str[]="I am thread1, I write a line\n";//线程要写入文件的字符串int i;printf("this is thread%d\n",*(int*)arg);while(1){pthread_mutex_lock(&mutex);//加入互斥锁//按字符将字符串循环写入文件for(i =0; i <strlen(str); i++){fputc(str[i], fp);usleep(1);}pthread_mutex_unlock(&mutex);//释放互斥锁pthread_testcancel();//设置线程取消点}sleep(10);pthread_exit("thread1 return");//退出线程}void*wrfunc2(void*arg){char str[]="I am thread2, I write a line\n";int i;printf("this is thread%d\n",*(int*)arg);while(1){pthread_mutex_lock(&mutex);for(i =0; i <strlen(str); i++){fputc(str[i], fp);usleep(1);}pthread_mutex_unlock(&mutex);pthread_testcancel();}sleep(10);pthread_exit("thread2 return");}void*wrfunc3(void*arg){char str[]="I am thread3, I write a line\n";int i;printf("this is thread%d\n",*(int*)arg);while(1){pthread_mutex_lock(&mutex);for(i =0; i <strlen(str); i++){fputc(str[i], fp);usleep(1);}pthread_mutex_unlock(&mutex);pthread_testcancel();}sleep(10);pthread_exit("thread3 return");}
#include <bits/stdc.h>
using namespace std;
using ll long long;
void solve(){string s;cin>>s;//s s;ll t;cin>>t;//t--;ll pos,k;ll len 0;for(int i 0 ; i < s.length() ; i){if(len s.length() - i > t){pos t - len;//第几个字符k i;…
Problem - F - Codeforces 思路:分析一下题意,对于第一种操作来说,每次乘以x,那么nn*x,然后问是否存在一个a使得gcd(n,a)1并且n*a的约数个数等于n,有最大公约数等于1我们能够知道其实这两个数是互质的&…
本文是LLM系列文章,针对《Meta Semantic Template for Evaluation of Large Language Models》的翻译。 大型语言模型评估的元语义模板 摘要1 引言2 相关工作3 方法4 实验5 结论 摘要
大型语言模型(llm)是否真正理解语言的语义,或者只是记住训练数据?…