View topic - what is pthread_attr_t ?

what is pthread_attr_t ?

anything that doesn't fit to other groups.

what is pthread_attr_t ?

Postby b_tamayo » Fri Jan 16, 2004 4:24 am

Hello Everyone,

I'm new to QNX API's and I really need some help. I dont understand the use of "pthread_attr_t". I saw a lot of sample programs for instance:

int main(){

pthread_attr_t attr;

pthread_attr_init(&attr);

pthread_create(NULL, &attr, &somefunction, NULL);

sleep(60);

return;

}

I undrstand that the programmer wants to initialize the attribute of that particular thread but by simply writing the following:

pthread_attr_t attr;

what attr is initialized to? and what is pthread_attr_t really ?


Thanks
bob
b_tamayo
New Member
 
Posts: 5
Joined: Fri Jan 16, 2004 4:12 am

Postby phearbear » Fri Jan 16, 2004 9:35 am

You can use the pthread_attr_t to change attributes on your thread, such as priority, scheduling type (fifo,RR,sporadic) etc
look at the pthread_atttr * functions in the helpviewer
phearbear
QNX Master
 
Posts: 110
Joined: Fri Jul 05, 2002 11:44 pm

Postby b_tamayo » Fri Jan 16, 2004 5:11 pm

Hi phearbear,

the code that iw rote above doesn't show that the "attr" is et to some value. Could you give me an example on how to initialize the attr?

Thanks
bob
b_tamayo
New Member
 
Posts: 5
Joined: Fri Jan 16, 2004 4:12 am

Postby xtang » Fri Jan 16, 2004 6:45 pm

pthread_attr_t is typedef'd in /usr/include/pthread.h as __PTHREAD_ATTR_T,
__PTHREAD_ATTR_T is defined in /usr/include/sys/target_nto.h, which is a
"struct _thread_attr".

pthread_attr_init(&attr);

This initialized the "attr" structure.
xtang
QNX Master
 
Posts: 313
Joined: Thu Jul 18, 2002 5:01 pm

Postby b_tamayo » Fri Jan 16, 2004 8:42 pm

xtang wrote:pthread_attr_t is typedef'd in /usr/include/pthread.h as __PTHREAD_ATTR_T,
__PTHREAD_ATTR_T is defined in /usr/include/sys/target_nto.h, which is a
"struct _thread_attr".

pthread_attr_init(&attr);

This initialized the "attr" structure.



Ok...but "attr" is initialized with what values?

Thanks
bob
b_tamayo
New Member
 
Posts: 5
Joined: Fri Jan 16, 2004 4:12 am

Postby cdm » Sun Jan 18, 2004 11:05 am

tamayo - it is setup to system defaults. If you read each of the attribute manipulation functions it will tell you the defaults. From the point-of-view of the user, the structure is opaque - you don't know what is inside of it.
cdm
QNX Master
 
Posts: 789
Joined: Fri Jul 05, 2002 9:38 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron