造梦西游吧吧 关注:144贴子:540
  • 4回复贴,共1
现在还有能用的修改器吗 求解啊!!!!!!!!!!!!!


1楼2014-01-16 18:31回复
    最好别用


    2楼2014-02-05 20:50
    回复

      瑾哥.我肝的


      3楼2021-09-19 17:57
      回复
        #include <stdio.h>
        #include <unistd.h>
        #include <stdlib.h>
        #include <sys/types.h>
        #include <semaphore.h>
        #include <fcntl.h>
        #include <wait.h>
        int main(){
        sem_t *sem = NULL;
        pid_t pid;
        pid = fork();
        setbuf(stdout,NULL);
        char msg[] = "This is the race condition test\n";
        char* ptr;
        int c;
        if (pid == 0){
        sem = sem_open("sem1", O_CREAT|O_RDWR, 0666, 1);
        for(int i=0; i < 10;i++)
        {
        sem_wait(sem);
        for(ptr = msg; (c = *ptr)!= 0; ptr++)
        putc(c,stdout);
        sem_post(sem);
        }
        sem_close(sem);
        }
        else {
        sem = sem_open("sem1", O_CREAT|O_RDWR, 0666, 1);
        for(int i=0; i < 10;i++)
        {
        sem_wait(sem);
        for(ptr = msg; (c = *ptr)!= 0; ptr++)
        putc(c,stdout);
        sem_post(sem);
        }
        sem_close(sem);
        wait(NULL);
        }
        sem_unlink("sem1");
        return 0;
        }


        IP属地:北京4楼2021-12-17 12:30
        回复
          #include <stdio.h>
          #include <unistd.h>
          #include <stdlib.h>
          #include <sys/types.h>
          #include <wait.h>
          int main(){
          pid_t pid;
          pid = fork(); // Create the new process
          setbuf(stdout,NULL); // Set unbuffered
          char msg[] = "This is the race condition test\n"; // used to show the race condition
          char* ptr;
          int c;
          // child process
          if (pid == 0){
          for(int i=0; i < 10;i++)
          {
          for(ptr = msg; (c = *ptr)!= 0; ptr++)
          putc(c,stdout);
          }
          }
          // parent process
          else {
          for(int i=0; i < 10;i++)
          {
          for(ptr = msg; (c = *ptr)!= 0; ptr++)
          putc(c,stdout);
          }
          wait(NULL);
          }
          return 0;
          }


          IP属地:北京5楼2021-12-17 12:32
          回复