comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: C++ primer on multithreading
Date: Fri, 22 Apr 2011 10:38:20 +0200
Date: 2011-04-22T10:38:21+02:00	[thread overview]
Message-ID: <1fr5ppc41ca7u.1oh598fh7fh9w.dlg@40tude.net> (raw)
In-Reply-To: 4c5fb8d6-7785-4c9f-bcf0-2bf6b3bb2cb0@e26g2000vbz.googlegroups.com

On Thu, 21 Apr 2011 14:03:20 -0700 (PDT), Maciej Sobczak wrote:

> On Apr 21, 8:58�am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> An interesting issue is the producer's behavior when the queue is full. I
>> presume it would fail
> 
> Or block. Being full is symmetric to being empty (hint: being full
> means that you run out of empty space, which means that the reserve of
> empty space is... empty :-) ).
> 
>> or the queue may grow infinitely (:-))
> 
> There are no infinite computers yet. You will get the out of memory
> condition, which in C++ is reported with an exception. This is handled
> cleanly: mutex will be automatically unlocked and consumers will not
> be affected.

Real-life implementations of n-to-1 queue I made, wait for a finite time
(typical response time limit 1-2s) and then throw an exception (e.g.
BusyFault). This is an equivalent of timed entry call in Ada. The queue may
grows up to a certain limit. 

>> You may need
>> an additional pulse event to handle this more reasonably.
> 
> What "pulse event"? They are not needed at all.

Pulse event is an event reset automatically after notification all waiting
threads. It can be used to unblock queueing threads which then start
grabbing the mutex. The event is set when the consumer removes an item from
the queue. Since pulse events are race condition exposed, certain care must
be taken.

BTW, there is no big difference on a single-core, but on a multi-core this
design compared to Ada's protected objects is still a bit wasting, because
producer threads may be really concurrent. An Ada implementation may just
release the first blocked producer without activating the whole clique.

In general multi-core threading is more fragile and has more "interesting"
issues than single-core. We keep on detecting some minor glitches in our
C++ software.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-04-22  8:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-20 10:45 C++ primer on multithreading Alex R. Mosteo
2011-04-20 11:23 ` Peter C. Chapin
2011-04-20 13:06   ` Alex R. Mosteo
2011-04-20 11:32 ` Dmitry A. Kazakov
2011-04-20 12:00 ` Maciej Sobczak
2011-04-20 13:04   ` Alex R. Mosteo
2011-04-20 14:34     ` Georg Bauhaus
2011-04-20 20:44     ` Maciej Sobczak
2011-04-21  8:50       ` Alex R. Mosteo
2011-04-21  6:58     ` Dmitry A. Kazakov
2011-04-21 21:03       ` Maciej Sobczak
2011-04-22  8:38         ` Dmitry A. Kazakov [this message]
2011-04-22 21:45           ` Maciej Sobczak
2011-04-23  6:51             ` Dmitry A. Kazakov
2011-04-23 21:35               ` Maciej Sobczak
2011-04-24  7:42                 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox