[so] Coada non-blocanta
Daniel Baluta
daniel.baluta at gmail.com
Tue Apr 3 16:27:26 EEST 2012
2012/4/3 Stanciu Alexandru <the_marian_2006 at yahoo.com>:
>
>
> ________________________________
> From: Daniel Baluta <daniel.baluta at gmail.com>
> To: Stanciu Alexandru <the_marian_2006 at yahoo.com>; Sisteme de Operare
> <so at cursuri.cs.pub.ro>
> Sent: Tuesday, April 3, 2012 6:18 AM
>
> Subject: Re: [so] Coada non-blocanta
>
> 2012/4/3 Stanciu Alexandru <the_marian_2006 at yahoo.com>:
>> ________________________________
>> From: Daniel Baluta <daniel.baluta at gmail.com>
>> To: Stanciu Alexandru <the_marian_2006 at yahoo.com>; Sisteme de Operare
>> <so at cursuri.cs.pub.ro>
>> Sent: Tuesday, April 3, 2012 6:07 AM
>> Subject: Re: [so] Coada non-blocanta
>>
>> 2012/4/3 Stanciu Alexandru <the_marian_2006 at yahoo.com>:
>>> Vreau sa fac si eu o coada non-blocanta, astfel incat, cand fac un
>>> receive
>>> sa nu se blocheze executia ci sa sara mai departe pana cand primeste
>>> ceva.
>>> Am facut asa:
>>>
>>> message_t *buf = (message_t*) calloc (1, sizeof(message_t));
>>>
>>> mqd_t q;
>>>
>>> struct mq_attr attr;
>>> attr.mq_flags = O_NONBLOCK;
>>> attr.mq_maxmsg = 10;
>>> attr.mq_msgsize = sizeof(message_t);
>>> attr.mq_curmsgs = 0;
>>>
>>> q = mq_open("/gateway", O_CREAT | O_RDWR, 0644, &attr);
>>>
>>> while(1)
>>> {
>>> rc = mq_receive(q, (char *)buf, sizeof(message_t), NULL);
>>
>> Ce se întâmplă dacă al treilea argument este sizeof(message_t) + 1?
>>
>>>
>>> In while, daca rc != -1 afisez datele din mesaj altfel un mesaj oarecare.
>>> Problema este ca coada se blocheaza. Poate sa-mi zici si mie cineva de ce
>>> coada mea este blocanta totusi? Afisam mesaj imediat dupa receive si nu
>>> ajungea acolo.
>>
>> Poți folosi strace să vezi apelurile de sistem făcute.
>>
>> strace ./program
>>
>> thanks,
>> Daniel
>>
>>
>> In apelul mq_open am pus attr si NU &attr si a mers.
>
> Imposibil! :)
>
> Am pus -1 la receive:). Daca pun la attr merge. Multumesc! Dar de ce a
> trebuit sa pun +1?
man mq_receive:
The msg_len argument specifies the size of the buffer pointed to by msg_ptr;
this must be greater than the mq_msgsize attribute of the queue.
thanks,
Daniel.
More information about the so
mailing list