Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - setting the prio of a thread at creation time: (2 Items)
   
setting the prio of a thread at creation time  
Hello,

that's my code:
	
/* create threads*/
	pthread_attr_init(&temptAttribute);
	param.sched_priority = 30;
	pthread_attr_setschedparam( &temptAttribute, ¶m );
	pthread_attr_setinheritsched( &temptAttribute, THREAD_EXPLICIT_SCHED );
	pthread_attr_setstacksize( &temptAttribute, 1024 );
	
	if ((ret = pthread_create(tHndl, &temptAttribute, ptFunc, pParams)) != 0) {
		printf(" * UserCreateThread: Thread creation failed %d\n", ret);
		return 0;
	}

It doesn't work as specified  .... what's wrong with it ??

Regards

--Armin Steinhoff

RE: setting the prio of a thread at creation time  
Works for me but, THREAD_EXPLICIT_SCHED doesn't exist on my setup? It's PTHREAD_EXCPLICIT_SCHED.  A typo?

This is the code I used based on your sample.  Compile it, ran it and check with pidin and the thread was at priority 30
.

#include <pthread.h>
#include <stdio.h>
#include <sys/neutrino.h> 
#include <sched.h>

void *ptFunc(void*arg)
{
sleep(100);
return NULL;
}

int main(void)

{
pthread_attr_t temptAttribute;
pthread_t tHndl;
struct sched_param param;
int ret=0;

	pthread_attr_init(&temptAttribute);
	param.sched_priority = 30;
	pthread_attr_setschedparam( &temptAttribute, ¶m );
	pthread_attr_setinheritsched( &temptAttribute, PTHREAD_EXPLICIT_SCHED );
	pthread_attr_setstacksize( &temptAttribute, 1024 );
	
	if ((ret = pthread_create(&tHndl, &temptAttribute, ptFunc, NULL)) != 0) {
		printf(" * UserCreateThread: Thread creation failed %d\n", ret);
		return 0;
	}

	sleep(100);

	return 0;
}

-----Original Message-----
From: Armin Steinhoff [mailto:community-noreply@qnx.com] 
Sent: Friday, July 17, 2009 4:26 PM
To: ostech-core_os
Subject: setting the prio of a thread at creation time


Hello,

that's my code:
	
/* create threads*/
	pthread_attr_init(&temptAttribute);
	param.sched_priority = 30;
	pthread_attr_setschedparam( &temptAttribute, ¶m );
	pthread_attr_setinheritsched( &temptAttribute, THREAD_EXPLICIT_SCHED );
	pthread_attr_setstacksize( &temptAttribute, 1024 );
	
	if ((ret = pthread_create(tHndl, &temptAttribute, ptFunc, pParams)) != 0) {
		printf(" * UserCreateThread: Thread creation failed %d\n", ret);
		return 0;
	}

It doesn't work as specified  .... what's wrong with it ??

Regards

--Armin Steinhoff



_______________________________________________
OSTech
http://community.qnx.com/sf/go/post34078