<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span><br></span></div><div><br></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>Am pus -1 la receive:). Daca pun la attr merge. Multumesc! Dar de ce a trebuit sa pun +1?<br><br><br><br> </div> </div> </div></body></html>