Skip navigation.
Home
The QNX Community Portal

View topic - More than one main... How is that possible?

More than one main... How is that possible?

For discussion of realtime and/or embedded programming.

RE: More than one main... How is that possible?

Postby mario » Thu Mar 19, 2009 9:58 pm

phtread_create (..., &argv )
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: More than one main... How is that possible?

Postby diogo_angnalo » Fri Mar 20, 2009 6:50 pm

and the declaration of the thread?

void * thread_mdan(char *argv[]){...} ?
void * thread_mdan(char *argv){...} ?
void * thread_mdan(void *argv[]){...} ?
void * thread_mdan(void *argv){...} ?

as I sad, I use argv like this:
IDMain = atoi(argv[0]);
Verbose=atoi(argv[1]);

I tried but, it didn't works... sorry piss you off... hehe

Thanks!
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

RE: More than one main... How is that possible?

Postby juanplacco » Fri Mar 20, 2009 7:18 pm

What do you want to do with this?

IDMain = atoi(argv[0]);

argv[0] is the name of the program... it's a char* ... I don't understand the idea of the atoi()...

JM
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: More than one main... How is that possible?

Postby juanplacco » Fri Mar 20, 2009 7:33 pm

I took 5 minutes to do this example, Is this what you're looking for?

void * thread_argv ( void *data )
{
char **argv = (char**) data;

printf ("I'm thread %d and the name of the proccess is: %s\n", pthread_self(), argv[0] );
}

int main ( int argc, char *argv[] )
{
pthread_attr_t
attrt;

time_t now;

memset ( &attrt, 0, sizeof (pthread_attr_t) );

printf ("%s - main() starting at %s", argv[0], ctime (&now));

pthread_create ( NULL, &attrt, thread_argv, (void*) argv );

sleep (1);

printf ("main() ending at %s", ctime (&now));

return ( EXIT_SUCCESS );
}
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: More than one main... How is that possible?

Postby diogo_angnalo » Fri Mar 20, 2009 7:39 pm

I don't know... I'm just adapting an existing program from qnx4 to QNX6...
I guess is the identification of the main... but I'm think that is not in use...
the verbose is used...

the atoi convert a string into an int isn't
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

RE: More than one main... How is that possible?

Postby diogo_angnalo » Fri Mar 20, 2009 7:56 pm

the argv[1] didn't work... any idea?




Thank you!
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

RE: More than one main... How is that possible?

Postby juanplacco » Fri Mar 20, 2009 8:32 pm

It works for me perfectly. Did you run the proccess with an extra argument, didn't you?
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: More than one main... How is that possible?

Postby juanplacco » Fri Mar 20, 2009 10:53 pm

Wow, my English is getting worse... :roll: ... Forget the 'didn't you?' part of the question
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: More than one main... How is that possible?

Postby diogo_angnalo » Mon Mar 23, 2009 2:40 pm

in the example you just use the argv[0]... in my code it works...
but the argv[1] don't...

I think that this don't make difference, but I'm creating the thread like this " pthread_create(NULL, NULL, &thread_mdan, (void*)argv); "

thanks..!
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

RE: More than one main... How is that possible?

Postby juanplacco » Mon Mar 23, 2009 3:26 pm

but the argv[1] don't...


Did you run the proccess for example:

./test_thread "Im_argv1" ??

If you don't give an extra arg to the command line, argv[1] will never exist, and the process will fail...

It should work fine.

Reagrds,
JM
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

RE: More than one main... How is that possible?

Postby diogo_angnalo » Mon Mar 23, 2009 4:25 pm

But I'm using QNX Momentics in Windows connected to QNX 6.4 ...
it's not by command line...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

RE: More than one main... How is that possible?

Postby juanplacco » Mon Mar 23, 2009 5:20 pm

Anyway!... you have to give an extra argument to your proccess when you run it!

You know who does the argv array works, don't you?... So, argv[0] is the full name of your proccess, argv[1] is the first argument and so on with argv[2,3...n]...

SO, if you want to print argv[1] you MUST run your proccess with that EXTRA parameter...

Am I clear?
juanplacco
Senior Member
 
Posts: 318
Joined: Wed May 17, 2006 2:30 pm

Postby diogo_angnalo » Mon Mar 23, 2009 6:33 pm

but how and where I put that extra parameter?

Thanks!


God bless...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

Re: RE: More than one main... How is that possible?

Postby mario » Mon Mar 23, 2009 6:34 pm

diogo_angnalo wrote:But I'm using QNX Momentics in Windows connected to QNX 6.4 ...
it's not by command line...


Yes it's a command line. In the run session you created you can specify arguments to be passed along. How can you expect argument from main() to be pass down to the thread if there is no argument ????

Seems to me you are trying to do something without understanding what you are actually doing or what need to be done.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: Re: RE: More than one main... How is that possible?

Postby diogo_angnalo » Mon Mar 23, 2009 7:01 pm

Yes, you're right... hehe

when you say "run session" you mean the "console"/"prompt"?
I don't know where and how pass these arguments... and I don't know if they are really necessary...
diogo_angnalo
Active Member
 
Posts: 38
Joined: Tue Feb 17, 2009 4:57 pm

PreviousNext

Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 1 guest

cron