|
xv.c
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main()
{
pid_t pc;
pc = fork();
if (pc==0)
{
char *argv[] ={"sh","/home/xfm/ShiHe/thread"};
execv("/bin/sh",argv);
return 0;
}
}
thread.c
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#pragma pack(4)
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /*......*/
pthread_cond_t cond = PTHREAD_COND_INITIALIZER; //.......
long Count = 0;
typedef unsigned char BOOL;
#define TRUE 1
#define FALSE 0
BOOL bFlag = TRUE;
void *threadA(void *X)
{
for(;;)
{
pthread_mutex_lock(&mutex);//
Count ++;
printf("1:%d\n",Count);
pthread_cond_wait(&cond,&mutex);/*..*/
pthread_cond_signal(&cond);/*............t_b..*/
pthread_mutex_unlock(&mutex);//*.....*/
sleep(1);
}
}
//------------------------------------------------------
void *threadB(void *X)
{
for (;;)
{
pthread_mutex_lock(&mutex);
Count ++;
printf("2:%d\n",Count);
pthread_cond_signal(&cond);/*............t_b..*/
pthread_cond_wait(&cond,&mutex);/*..*/
pthread_mutex_unlock(&mutex);
sleep(1);
}
}
//------------------------------------------------------
int main(void)
{
pthread_t ThreadA;
pthread_t ThreadB;
pthread_create(&ThreadA,NULL,threadA,NULL);
pthread_create(&ThreadB,NULL,threadB,NULL);
pthread_join(ThreadA,NULL);
pthread_join(ThreadB,NULL);
return 0;
}
xv.c 调用thread.c后出现 /home/xfm/ShiHe/thread: cannot execute binary file
这是为什么
帮忙,如何能正确调用 |
|