I starting working with concurrency features and created this little example to work with channels:
Code: Select all
transaction thing1( chanend channel )
{
while( 1 )
{
channel <: 'a';
}
}
transaction thing2( chanend channel )
{
char thing;
while( 1 )
{
channel :> thing;
printchar(thing);
}
}
int dr_suess()
{
chan thread_channel;
par {
master { thing1(thread_channel);}
slave { thing2(thread_channel);}
}
return 0;
}
int main()
{
par
{
on stdcore[IO_CORE] : dr_suess();
}
return 0;
}
I figured it would just blaze but it's about 2400 baud.
I also tried this (no transactions):
Code: Select all
void thing1( chanend channel )
{
while( 1 )
{
channel <: 'a';
}
}
void thing2( chanend channel )
{
char thing;
while( 1 )
{
channel :> thing;
printchar(thing);
}
}
int dr_suess()
{
chan thread_channel;
par {
thing1(thread_channel);
thing2(thread_channel);
}
return 0;
}
Also tried it with this variation (skipped dr_suess() thread):
Code: Select all
int main()
{
chan thread_channel;
par
{
// on stdcore[IO_CORE] : dr_suess();
on stdcore[IO_CORE] : thing1(thread_channel);
on stdcore[IO_CORE] : thing2(thread_channel);
}
return 0;
}
I doubt anything is "wrong" per se, except I don't understand why it's so slow....I suppose printchar() could be blocking, but it's only got one character to push, so I didn't think it would hang things up that much. Maybe my expectations are whacked.
I expected thing1() to quickly fill up the channel and then block...when I think of blocking I think of the thread then yielding, but maybe I'm conceptually broken. I could see it blocking....then timing out the thread before thing2() got run...is that why it's slow?
What's a better way to get the kind of fast output you would expect to see when one thread is constantly feeding another data via a channel? Is there a concept of a thread yielding when it blocks?
Landon