Click here to Skip to main content
15,916,941 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
Questionneed a similar function as "getchar()" Pin
bloodwinner10-Jul-07 22:00
bloodwinner10-Jul-07 22:00 
AnswerRe: need a similar function as "getchar()" Pin
Christian Graus11-Jul-07 0:42
protectorChristian Graus11-Jul-07 0:42 
QuestionWhat's the meaning of ^ in VS2005.NET??? Pin
Ming Luo10-Jul-07 7:30
Ming Luo10-Jul-07 7:30 
AnswerRe: What's the meaning of ^ in VS2005.NET??? Pin
Giorgi Dalakishvili10-Jul-07 8:10
mentorGiorgi Dalakishvili10-Jul-07 8:10 
GeneralRe: What's the meaning of ^ in VS2005.NET??? Pin
Ming Luo10-Jul-07 8:12
Ming Luo10-Jul-07 8:12 
GeneralRe: What's the meaning of ^ in VS2005.NET??? Pin
iddqd51510-Jul-07 8:37
iddqd51510-Jul-07 8:37 
Questiondeclaration classe and methodes c++ cli Pin
abbd10-Jul-07 6:13
abbd10-Jul-07 6:13 
Questionhow to keep on this program executing when I put it at the backgound? Pin
bloodwinner9-Jul-07 23:20
bloodwinner9-Jul-07 23:20 
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.




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 />
}

AnswerRe: how to keep on this program executing when I put it at the backgound? Pin
Christian Graus10-Jul-07 1:35
protectorChristian Graus10-Jul-07 1:35 
QuestionMatlab/C communication Pin
gregdachs9-Jul-07 15:09
gregdachs9-Jul-07 15:09 
AnswerRe: Matlab/C communication Pin
Christian Graus9-Jul-07 15:14
protectorChristian Graus9-Jul-07 15:14 
QuestionKeyboard send Message Pin
WonYG9-Jul-07 14:43
WonYG9-Jul-07 14:43 
AnswerRe: Keyboard send Message Pin
Christian Graus9-Jul-07 15:36
protectorChristian Graus9-Jul-07 15:36 
AnswerRe: Keyboard send Message Pin
Hamid_RT10-Jul-07 9:09
Hamid_RT10-Jul-07 9:09 
QuestionCxImage library Pin
Bieras9-Jul-07 7:50
Bieras9-Jul-07 7:50 
AnswerRe: CxImage library Pin
Mark Salsbery9-Jul-07 8:51
Mark Salsbery9-Jul-07 8:51 
GeneralRe: CxImage library Pin
Bieras9-Jul-07 10:59
Bieras9-Jul-07 10:59 
GeneralRe: CxImage library Pin
Mark Salsbery9-Jul-07 11:10
Mark Salsbery9-Jul-07 11:10 
QuestionWhat's the equivalent to C# static classes? Pin
mid=57417-Jul-07 6:36
mid=57417-Jul-07 6:36 
AnswerRe: What's the equivalent to C# static classes? Pin
Mark Salsbery7-Jul-07 7:27
Mark Salsbery7-Jul-07 7:27 
GeneralRe: What's the equivalent to C# static classes? Pin
mid=57417-Jul-07 7:34
mid=57417-Jul-07 7:34 
GeneralRe: What's the equivalent to C# static classes? Pin
Mark Salsbery7-Jul-07 8:04
Mark Salsbery7-Jul-07 8:04 
GeneralRe: What's the equivalent to C# static classes? Pin
mid=57417-Jul-07 8:08
mid=57417-Jul-07 8:08 
GeneralRe: What's the equivalent to C# static classes? Pin
Mark Salsbery7-Jul-07 9:07
Mark Salsbery7-Jul-07 9:07 
Questionunresolved external symbol error when using template function Pin
patrick.steal7-Jul-07 1:40
patrick.steal7-Jul-07 1:40 

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.