23,223
社区成员
发帖
与我相关
我的任务
分享
#include <sys/types.h>
#include <linux/unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#define gettid() syscall(__NR_gettid)
#define LENGTH 64
int buf[LENGTH];
void Func(int sig)
{
pid_t threadId = gettid();
printf("Thread Id is :%d\n", (int)threadId);
int item = buf[0];
int i;
for(i = 0;i < LENGTH; ++i)
{
if (buf[i] != item)
{
printf("Error!\n");
break;
}
}
printf("Begin.\n");
for(i = 0; i < LENGTH; ++i)
{
printf("%d", buf[i]);
}
printf("\nEnd.\n");
}
int main()
{
pid_t threadId = gettid();
printf("Thread Id is :%d\n", (int)threadId);
signal(SIGALRM, Func);
alarm(2);
int a = 0;
while(1)
{
int i;
for(i = 0; i < LENGTH; ++i)
{
buf[i] = a;
}
a = (a + 1) & 1;
}
return 0;
}