Skip to contentSkip to conversation

good pthreads example?

DISCUSSION Jason Cooper 2 participants 3 messages Sep 21, 2003 – Sep 22, 2003

lore
Share & tools
lore
#0 lore raw

Hey all,

I've been learning pthreads for the past week or so. So far, I've read through the man pages, "Pthreads Programming" from O'Reilly, an old copy of POSIX 4, and other various google searches.

What I'm looking for is a good example (open source, of course) of pthreads in practice. It doesn't matter whether it's boss/worker, peer/peer, or assembly line. I'm looking for practical examples to learn from.

The O'Reilly book has a good ATM (cash machine, client/server) example, but it isn't implemented in the real world...

TIA,

Cooper.

PS - I know grepping through source will provide plenty of examples of pthreads in action, but I wouldn't know if they are sound implementations or not.

#1 lore raw

Hi Cooper,

I donno whether this basic example will be enough for ur requirement, anyway here it is, You can try creating the thread like...
void func(void);
main()
{
pthread_t tid;
retVal = pthread_create(&tid, NULL, (void *)func, (void *) NULL);
/* validate here with retVal */
}

void
func(void)
{
pthread_detach(pthread_self()); /* if detached thread */ /* some printf */
}

Pls ignore if this is very basic.

Regards
-Raghu

Quoted 27 lines · Jason Cooper

Hey all,

I've been learning pthreads for the past week or so. So far, I've read through the man pages, "Pthreads Programming" from O'Reilly, an old copy of POSIX 4, and other various google searches.

What I'm looking for is a good example (open source, of course) of pthreads in practice. It doesn't matter whether it's boss/worker, peer/peer, or assembly line. I'm looking for practical examples to
learn from.

The O'Reilly book has a good ATM (cash machine, client/server) example, but it isn't implemented in the real world...

TIA,

Cooper.

PS - I know grepping through source will provide plenty of examples of pthreads in action, but I wouldn't know if they are sound implementations or not.
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Raghuveer ([email protected]) scribbled:

Quoted 20 lines

Hi Cooper,

I donno whether this basic example will be enough for ur requirement, anyway here it is,
You can try creating the thread like...
void func(void);
main()

{
   pthread_t tid;
   retVal = pthread_create(&tid, NULL, (void *)func, (void *) NULL);
   /* validate here with retVal */
}

void
func(void)
{
pthread_detach(pthread_self()); /* if detached thread */ /* some printf */
}

Quoted 29 lines

Pls ignore if this is very basic.

Regards
-Raghu

Quoted 21 lines · Jason Cooper

Hey all,

I've been learning pthreads for the past week or so. So far, I've read through the man pages, "Pthreads Programming" from O'Reilly, an old copy of POSIX 4, and other various google searches.

What I'm looking for is a good example (open source, of course) of pthreads in practice. It doesn't matter whether it's boss/worker, peer/peer, or assembly line. I'm looking for practical examples to learn from.

The O'Reilly book has a good ATM (cash machine, client/server) example, but it isn't implemented in the real world...

TIA,

Cooper.

PS - I know grepping through source will provide plenty of examples of pthreads in action, but I wouldn't know if they are sound implementations or not.

Thanks for the reply, unfortunately, what I'm looking for is a recommendation of a good FS/OSS package to look at which implements pthreads.

As usual, my long-windedness confused the issue :)

Cooper.