|
这时一个关于pv操作的程序
void main(int argc,char**argv)
{
int sem_set_id;
int rc,r,child_pid;
int i,j;
sem_set_id=semget(250,3,IPC_CREAT|0600);
if(sem_set_id==-1) exit(-1);
rc=semctl(sem_set_id,0,SETVAL,1);
if(rc==-1) exit(-1);
rc=semctl(sem_set_id,1,SETVAL,0);
if(rc==-1) exit(-1);
rc=semctl(sem_set_id,2,SETVAL,20);
if(rc==-1) exit(-1);
child_pid=fork();
switch(child_pid){
case -1:exit(-1);
case 0: for(i=1;i<=60;i++){
cwait(sem_set_id,1);
cwait(sem_set_id,0);
QMessageBox::information( this,"continue","consume",QMessageBox::Ok);
csignal(sem_set_id,0);
csignal(sem_set_id,2);
}
exit(0);
default: for(j=1;j<=60;j++){
cwait(sem_set_id,2);
cwait(sem_set_id,0);
QMessageBox::information( this, "continue","produce",QMessageBox::Ok);
csignal(sem_set_id,0);
csignal(sem_set_id,1);
}
break;
}
wait(&r);
exit(0);
}
函数cwait(int sem_set_id,int i)将信号量i的值减1
函数csignal(int sem_set_id,int i)将信号量i的值加1
为什么父进程在j等于20时候运行完QMessageBox::information( this, "continue","produce",QMessageBox::Ok);后立即睡眠,直接跳到子进程的QMessageBox::information( this, "continue","produce",QMessageBox::Ok);
到底怎么回事?
我是用kdevelop运行的,标准错误输出里有如下这么一些错误:
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 70
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 67
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 66
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 66
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 70
Minor opcode: 0
Resource id: 0x340002e
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 6
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 23
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 6
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 5
Resource id: 0x340002f
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 67
Minor opcode: 0
Resource id: 0x340002e
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 5
Resource id: 0x340002f
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62
Minor opcode: 0
Resource id: 0x340002e
Xlib: unexpected async reply (sequence 0x2b1f)!
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 70
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 67
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 66
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 66
Minor opcode: 0
Resource id: 0x340002e
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 70
Minor opcode: 0
Resource id: 0x340002e
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 6
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 23
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 6
Resource id: 0x340002f
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 5
Resource id: 0x340002f
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 67
Minor opcode: 0
Resource id: 0x340002e
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 5
Resource id: 0x340002f
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62
Minor opcode: 0
Resource id: 0x340002e
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
Major opcode: 53
Minor opcode: 0
Resource id: 0x3400048
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 62
Minor opcode: 0
Resource id: 0x340002e
X Error: RenderBadPicture (invalid Picture parameter) 183
Major opcode: 155
Minor opcode: 7
Resource id: 0x340002f
X Error: BadPixmap (invalid Pixmap parameter) 4
Major opcode: 54
Minor opcode: 0
Resource id: 0x340002e
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
Major opcode: 155
Minor opcode: 4
Resource id: 0x3400049
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
Major opcode: 55
Minor opcode: 0
Resource id: 0x340004d
X Error: BadIDChoice (invalid resource ID chosen for this connection) 14
Major opcode: 53
Minor opcode: 0
Resource id: 0x3400058
X Error: BadDrawable (invalid Pixmap or Window parameter) 9
Major opcode: 72
Minor opcode: 0
Resource id: 0x3400058
Xlib: unexpected async reply (sequence 0x30bb)!
X Error: BadAtom (invalid Atom parameter) 5
Major opcode: 18
Minor opcode: 0
Resource id: 0x3400005 |
|