<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div> </div> <div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><div dir="ltr"><font face="Arial" size="2"><hr size="1"> <b><span style="font-weight: bold;">From:</span></b> Daniel Baluta <daniel.baluta@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> Stanciu Alexandru <the_marian_2006@yahoo.com>; Sisteme de Operare <so@cursuri.cs.pub.ro> <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, April 3, 2012 6:18 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [so] Coada non-blocanta<br> </font> </div> <br>
2012/4/3 Stanciu Alexandru <<a ymailto="mailto:the_marian_2006@yahoo.com" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>:<br>> ________________________________<br>> From: Daniel Baluta <<a ymailto="mailto:daniel.baluta@gmail.com" href="mailto:daniel.baluta@gmail.com">daniel.baluta@gmail.com</a>><br>> To: Stanciu Alexandru <<a ymailto="mailto:the_marian_2006@yahoo.com" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>; Sisteme de Operare<br>> <<a ymailto="mailto:so@cursuri.cs.pub.ro" href="mailto:so@cursuri.cs.pub.ro">so@cursuri.cs.pub.ro</a>><br>> Sent: Tuesday, April 3, 2012 6:07 AM<br>> Subject: Re: [so] Coada non-blocanta<br>><br>> 2012/4/3 Stanciu Alexandru <<a ymailto="mailto:the_marian_2006@yahoo.com" href="mailto:the_marian_2006@yahoo.com">the_marian_2006@yahoo.com</a>>:<br>>> Vreau sa fac si eu o coada non-blocanta, astfel incat, cand fac un
receive<br>>> sa nu se blocheze executia ci sa sara mai departe pana cand primeste ceva.<br>>> Am facut asa:<br>>><br>>> message_t *buf = (message_t*) calloc (1, sizeof(message_t));<br>>><br>>> mqd_t q;<br>>><br>>> struct mq_attr attr;<br>>> attr.mq_flags = O_NONBLOCK;<br>>> attr.mq_maxmsg = 10;<br>>> attr.mq_msgsize = sizeof(message_t);<br>>> attr.mq_curmsgs = 0;<br>>><br>>> q = mq_open("/gateway", O_CREAT | O_RDWR, 0644, &attr);<br>>><br>>> while(1)<br>>> {<br>>> rc = mq_receive(q, (char *)buf, sizeof(message_t), NULL);<br>><br>> Ce se întâmplă dacă al treilea argument este sizeof(message_t) + 1?<br>><br>>><br>>> In while, daca rc
!= -1 afisez datele din mesaj altfel un mesaj oarecare.<br>>> Problema este ca coada se blocheaza. Poate sa-mi zici si mie cineva de ce<br>>> coada mea este blocanta totusi? Afisam mesaj imediat dupa receive si nu<br>>> ajungea acolo.<br>><br>> Poți folosi strace să vezi apelurile de sistem făcute.<br>><br>> strace ./program<br>><br>> thanks,<br>> Daniel<br>><br>><br>> In apelul mq_open am pus attr si NU &attr si a mers.<br><br>Imposibil! :)<br><br>Ai dreptate. M-am bucurat prea repede:). Am pus +1 acolo, degeaba, am dat cu strace ala:<br><br>mq_timedreceive(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 47, 0, NULL) = ? ERESTARTSYS (To be restarted)<br>--- SIGWINCH (Window changed) @ 0 (0) ---<br>mq_timedreceive(3, "poa\0\0\0\0\0\23\0\0\0\1\0\377\377\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 47, 0, NULL) = 46<br>fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...})
= 0<br>mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb783e000<br>write(1, "poa\n", 4poa<br>) = 4<br>write(1, "19\n", 319<br>) = 3<br>mq_timedreceive(3, <br><br>Si ramane asa. Nu stiu ce ar trebui sa vad aici:)<br><br> </div> </div> </div></body></html>