Search the web
Sign In
New User? Sign Up
cheapthreads · cheap_threads
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
multithreaded paradigm   Message List  
Reply | Forward Message #16 of 89 |
Re: [cheapthreads] multithreaded paradigm

You're asking about non-blocking IO, and the question
is not at all trivial.
 
For many forms of multithreading, there's no problem. 
One thread can perform blocking IO, through scanf() or

whatever, and the other threads can keep running while

the first thread waits.  That's a major reason for
using threads in the first place.
 
Cheap Threads isn't like that.  If one thread blocks
for any reason, all threads are blocked.  If you want
to perform non-blocking IO, you'll have to use some
platform-specific way to do it, because Standard C
doesn't provide this capability.

I do most of my Cheap Threads development on an
ancient Borland compiler.  Borland provides a kbhit
function that tells you whether there is a keypress
waiting in the keyboard buffer.  By using that
function, I can read the next keypress (potentially a
blocking operation) only when I know there's
a keypress to be read.  At one time Microsoft's
compiler provided a similar kbhit function, but I
don't know about their current offerings.
 
One of my main testbed programs has several input
fields, each run by a separate thread.  Another thread

checks the keyboard buffer and, if it detects a
keypress, passes it in a message to whatever input
field currently has focus.  It's actually a bit more
complicated than that, but the point is that the user
interface is event-driven, and every keypress is an
event.  This approach is rather more tedious than
using scanf(), especially if you want to handle
backspaces, delete keys, tabs, and arrow keys
sensibly, but it does enable background threads to do
work between keypresses.
 
Depending on what's available on your platform, you
may be able to use a similar approach.  I don't know
of any Unix equivalent to kbhit, but maybe someone
else in the group does.  Otherwise you're probably
better off using some other form of multithreading
such as POSIX threads, or maybe a separate process for

the background work.

Scott McKellar
http://home.swbell.net/mck9/ct/

xcelcior <blaze01211983@...> wrote:

> GREETINGS
> forgive me but I'm kinda new to multithreaded
programming d=)

> I'm just wondering how to implement a user interface
in a
> multithreaded programming environment or using cheap
thread.

> For example i have 2 threads. Thread A runs the user
interface while
> Thread B does other things. I mean how do i get the
input from the
> user through thread A since the two threads are
switching controls.
> I cant use scanf since it will wait for user input
at the same time
> suspending the execution of the other thread Thread
B.

>How can I run thread B on the background while thread
A gets user
> input?

> Forgive me if my question is a bit trivial =)




Fri Sep 12, 2003 5:29 pm

jm407a
Offline Offline
Send Email Send Email

Forward
Message #16 of 89 |
Expand Messages Author Sort by Date

GREETINGS forgive me but I'm kinda new to multithreaded programming d=) I'm just wondering how to implement a user interface in a multithreaded programming...
xcelcior
blaze01211983
Offline Send Email
Sep 12, 2003
1:32 pm

You're asking about non-blocking IO, and the question is not at all trivial.   For many forms of multithreading, there's no problem.  One thread can perform...
Scott McKellar
jm407a
Offline Send Email
Sep 12, 2003
5:29 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help