[so] Coada non-blocanta

Stanciu Alexandru the_marian_2006 at yahoo.com
Tue Apr 3 17:23:54 EEST 2012


________________________________
 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:27 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: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.

Tot nu este bine:(. Daca dau la attr sizeof(message_t) + 1 intradevar nu mai este blocanta, dar cand fac receive, cu buffer size egal cu sizeof(message_t) nu preia mesajul si se blocheaza; daca dau buffer size in receive egal cu sizeof(message_t) + 1 imi preia mesajul, dar coada este iar blocanta, adica daca nu trimit ceva nu mai trece de receive. Care ar mai fi problema acum?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20120403/57fa49ef/attachment.htm>


More information about the so mailing list