Click here to Skip to main content
15,924,507 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: about "round" function in visual C++ Pin
Russell'10-Jul-07 3:10
Russell'10-Jul-07 3:10 
QuestionOLEDB WITH .CDX Pin
ArielR10-Jul-07 2:23
ArielR10-Jul-07 2:23 
QuestionGet cookie from the url/web? Pin
bosfan10-Jul-07 1:43
bosfan10-Jul-07 1:43 
AnswerRe: Get cookie from the url/web? Pin
_AnsHUMAN_ 10-Jul-07 2:10
_AnsHUMAN_ 10-Jul-07 2:10 
GeneralRe: Get cookie from the url/web? Pin
bosfan10-Jul-07 3:44
bosfan10-Jul-07 3:44 
AnswerRe: Get cookie from the url/web? Pin
David Crow10-Jul-07 3:09
David Crow10-Jul-07 3:09 
GeneralRe: Get cookie from the url/web? Pin
bosfan10-Jul-07 3:45
bosfan10-Jul-07 3:45 
Questionhow to keep on this program executing when I put it at the backgound? Pin
bloodwinner10-Jul-07 1:38
bloodwinner10-Jul-07 1:38 
the scenario is I am counting down 5, if no 'y' has been input during this time, then it ends at one way, else it ends at another way. Because I dont expect there must be a 'y' input, I write this as multi-thread, one for counting down, one for checking the 'y' input (could be unnecessary).

this program works fine when I put it at the foreground(using linux), but when put it at background, error happens, it will stop and wait for getchar() input, and m doesnot count down. As long as I use shell command "fg" to bring it back to foreground, the count down resumes, but that is not what I want.

what I want is just: put the program execution at background, while waiting for a 'y' input during 5 seconds count down time.



<br />
void *countdown( );<br />
void *waitinput( );<br />
static int m=5;<br />
static int k=1;<br />
<br />
int main(int argc, char **argv)<br />
{<br />
<br />
pthread_t thread1=0, thread2=0;<br />
int iret1=0, iret2=0;<br />
<br />
/* Create independent threads each of which will execute function */<br />
<br />
iret1 = pthread_create( &thread1, NULL, countdown, NULL);<br />
iret2 = pthread_create( &thread2, NULL, waitinput, NULL);<br />
<br />
/* Wait till threads are complete before main continues. Unless we */<br />
/* wait we run the risk of executing an exit which will terminate */<br />
/* the process and all threads before the threads have completed. */<br />
<br />
pthread_join( thread1, NULL);<br />
// pthread_join( thread2, NULL);<br />
<br />
pthread_cancel(thread1);<br />
pthread_cancel(thread2);<br />
printf("pthread been cancelled\n\n");<br />
<br />
if(k=1){...}<br />
else {...}<br />
<br />
<br />
return 0;<br />
}<br />
<br />
void *countdown()<br />
{<br />
while(m>0)<br />
{<br />
printf("%d seconds left\n",m--);<br />
sleep(1);<br />
printf("m is %d\n",m);<br />
}<br />
<br />
}<br />
<br />
void *waitinput()<br />
{<br />
char c='n';<br />
while(m)<br />
{<br />
if((c=getchar())=='y')<br />
{<br />
printf("congratulations. you entered y\n");<br />
sleep(1);<br />
m=0;k=0;<br />
}<br />
else ;<br />
}<br />
}<br />

AnswerRe: how to keep on this program executing when I put it at the backgound? Pin
Rage10-Jul-07 1:55
professionalRage10-Jul-07 1:55 
GeneralRe: how to keep on this program executing when I put it at the backgound? Pin
bloodwinner10-Jul-07 2:22
bloodwinner10-Jul-07 2:22 
AnswerRe: how to keep on this program executing when I put it at the backgound? Pin
InOut.NET10-Jul-07 2:13
InOut.NET10-Jul-07 2:13 
GeneralRe: how to keep on this program executing when I put it at the backgound? Pin
bloodwinner10-Jul-07 2:24
bloodwinner10-Jul-07 2:24 
GeneralRe: how to keep on this program executing when I put it at the backgound? Pin
InOut.NET10-Jul-07 3:14
InOut.NET10-Jul-07 3:14 
QuestionAdding Controls in Runtime Pin
InOut.NET10-Jul-07 1:23
InOut.NET10-Jul-07 1:23 
AnswerRe: Adding Controls in Runtime Pin
Hamid_RT10-Jul-07 1:36
Hamid_RT10-Jul-07 1:36 
AnswerRe: Adding Controls in Runtime Pin
Mark Salsbery10-Jul-07 6:24
Mark Salsbery10-Jul-07 6:24 
GeneralRe: Adding Controls in Runtime Pin
InOut.NET10-Jul-07 7:01
InOut.NET10-Jul-07 7:01 
GeneralRe: Adding Controls in Runtime Pin
Mark Salsbery10-Jul-07 7:03
Mark Salsbery10-Jul-07 7:03 
Questionbackground bitmaps disappearing Pin
chaitu_41210-Jul-07 1:09
chaitu_41210-Jul-07 1:09 
AnswerRe: background bitmaps disappearing Pin
Christian Graus10-Jul-07 1:16
protectorChristian Graus10-Jul-07 1:16 
GeneralRe: background bitmaps disappearing Pin
chaitu_41210-Jul-07 1:22
chaitu_41210-Jul-07 1:22 
Questionpass values in dsn at runtime Pin
meenakhisjoshi10-Jul-07 0:59
meenakhisjoshi10-Jul-07 0:59 
AnswerRe: pass values in dsn at runtime Pin
David Crow10-Jul-07 3:15
David Crow10-Jul-07 3:15 
Questionabout "round" function in visual C++ Pin
mt_samiei10-Jul-07 0:34
mt_samiei10-Jul-07 0:34 
AnswerRe: about &quot;round&quot; function in visual C++ [modified] Pin
CPallini10-Jul-07 0:53
mveCPallini10-Jul-07 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.