Boost logo

Boost Users :

From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2008-03-17 11:53:06


On Mon, Mar 17, 2008 at 11:17:59AM -0400, Hal Vaughan wrote:
>
> thread 2 could start, is that the same? Is there any way I can get the two
> threads to run concurrently? (I know true multi-tasking on a single CPU is
>
Yes, you need to properly synchronize between them. Thread A has to
explicitly signal thread B to start running (while A puts itself to sleep).
If you don't use such signalling, the OS has all right to assume that you
don't care about the scheduling order.

>
> just slicing up time, but by concurrently, I mean sharing resources instead
> of one taking up everything.)
>
"Sharing resources" is very vaguely defined. If thread A runs for 30 seconds,
and then B for 30 seconds without interruption, they will still have received
their fair share of resources if the total run time of the program is, say,
1 hour.

> This is just a test program, but my big concern is that the program I'm
> writing does something like this. I'm controlling an HD radio through the
> serial port (or a usb port with a usb->RS232 adaptor). I know once I
> mention ports, I'm getting into OS specific stuff, but even beyond that
> issue, I'm trying to understand what I need to do and what's going on.
>

>
> title, artist name, and so on. To read the port this way, I'm using an
> ifstream object to open the port as a file, which seems to work well
> because it's buffered. Then, in another thread, I write the commands to
>
Using buffered I/O with external devices is a bad idea, IMHO.

>
> This all goes in a library where the listening thread can be started and
> stopped. I don't want to miss incoming data on the ifstream object, but it
> seems if I let that thread run on it's own, the other thread to pass on
>
The thread won't be running on its own if there's no data - it'll go to sleep
and other threads will be scheduled.

>
> I know in Perl I can fork and have one thread continue to do it's own thing
> without it seeming to effect the other. I also know Perl is a much higher
>
I don't think that Perl's threads are "real" OS-threads.

>
> So is there no way to create a thread and not have it take up all the CPU
> time until it's done without using SMP? (This is going to be for
>
Well, yes, threads sleep on I/O when I/O is not possible at the given moment.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net