UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Threads
  • » Launching more than 1 thread on the SAME pthread_t

#1 2003-11-05 08:29 AM

bzchevalier
Member
Registered: 2003-09-04
Posts: 40

Re: Launching more than 1 thread on the SAME pthread_t

pthread_t f_thr;
void* func_thr(void* inutile);

int
main (int argc, char *argv[], char *envp[])
{
int ret;
int i;
void* retour_func_thr;
pthread_t thread_00;

/* Création threads */ 
for (i=0 ; i<10 ; i++)
	{
	if ((ret = pthread_create(&thread_00,NULL,func_thr,(void*)i)) != 0)
		{
		fprintf(stderr,"\nEchec création thr %d   ret=%d",i,ret);
		}
	usleep(100000);
	}


for (i=0 ; i<10 ; i++)
	{
	ret=pthread_join(thread_00,(void**)&retour_func_thr);
	if (ret==0)
		fprintf(stderr,"\nReturned value : %d", (int)retour_func_thr);
	else 
		fprintf(stderr,"\nERREUR : %d", ret);

	if (!(i%4) && i)	// temporization every 4 join()
		{
		fprintf(stderr,"\nModulo 4");
		usleep(1); 
		}
	}
}

void* func_thr(void* inutile)
{
fprintf(stderr,"\n[BEGIN] (func_thr) thread # %d",(int)inutile);
sleep(3);	/* artificial delay - processing simulation */ 
fprintf(stderr,"\n[END] (func_thr) thread # %d",(int)inutile);
fflush(stderr);
pthread_exit((void*) inutile);
}

Offline

#2 2003-11-06 08:03 PM

HectorLasso
Administrator
From: Colombia
Registered: 2002-06-12
Posts: 353

Re: Launching more than 1 thread on the SAME pthread_t

Offline

#3 2003-11-12 08:31 AM

bzchevalier
Member
Registered: 2003-09-04
Posts: 40

Re: Launching more than 1 thread on the SAME pthread_t

int  pthread_create(pthread_t  *  thread, pthread_attr_t * attr, void * (*start_routine)(void *),
                           void * arg);

Offline

#4 2006-08-26 12:04 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: Launching more than 1 thread on the SAME pthread_t

Old message ... but looking at the list of what is currently being viewed by users and saw
this thread...

Even though its old... a bit of clarification...

Yes...

Each call to pthread_create will over-write the prior data of the passed in pthread_t variable ( after all - its a pointer )... and according to the spec doesn't care about passed in info EXCEPT that its the proper type... meaning you have to use a new pthread_t var each time if you want to do tracking... ref Loco's msg..

Nope... you cannot chose the ids assigned to specific threads... its done by the system on creation...

Nope... the ids are NOT guaranteed to be globally unique on a system...  its only guaranted that two equal ids won't exist simultaneously for LIVE threads...

Nope... or at least a partial nope...  some systems DO use things like int types etc. as the pthread ids... but trust me... don't depend on it...  the spec allows them to by ANYTHING including complex structures... so basic equality checks, copies and so forth should not be depended upon... and pthread_equal should be used instead...

Can anyone else tell I'm bored?


Michael


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

  • Index
  • » Threads
  • » Launching more than 1 thread on the SAME pthread_t

Board footer

Powered by FluxBB