Sponsored Content
Top Forums Programming MultiThreading using Pthreads Post 302380143 by Sastra on Monday 14th of December 2009 11:03:29 AM
Old 12-14-2009
MultiThreading using Pthreads

Situation:
i have multiple pthread_create calls like this:

pthread_create(...., ThreadFunc1,.....);
pthread_create(...., ThreadFunc2,.....);
.
.

which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same object of that class like this:

ThreadFunc1()
obj.Receive(<socket 1>); //receive data from socket 1

ThreadFunc2()
obj.Receive(<socket 2>); //receive data from socket 2

Question:
1.Will all the threads have their own copies of function "Receive", in order to provide concurrent receiving from all the receive sockets in application.

2. How is this approach different from:

while(1)
obj.Receive(<from all sockets one by one>);

where the same function polls all the receive sockets one by one to see for any data on them.
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

PThreads

Can anyone explain me how to use pthread_key_create() , pthread_setspecific(), pthread_getspecific() and pthread_key_delete () routines in pthreads. Kindly state by an example. (3 Replies)
Discussion started by: S.P.Prasad
3 Replies

2. Programming

pthreads

Does any one no of some good web site which will explain about how to program using pthreads in a UNIX enviroment? (6 Replies)
Discussion started by: fishman2001
6 Replies

3. Programming

pthreads

howcome that pthtreads spawn 2 extra processes? I'm kind of new with pthreads but fork() did not act like this. Anyone who can give me a technical explanation of what happends with mother / daughter processes? Best regards Esaia. (2 Replies)
Discussion started by: Esaia
2 Replies

4. Programming

PThreads

I have created a thread program, it is attached. My problem is that I need to loop this program multiple times, and basically reset everything including the threads created previously. I try to loop the program, the first run is fine, as always, but the second run of the program, the initialize... (0 Replies)
Discussion started by: justgotthis
0 Replies

5. HP-UX

pthreads

Hi! I'm linking my hpux code using -lpthread (gcc), yet it references libpthread_tr.1, the debug version of the pthread lib. How do I force it to use pthreads? Thanks, :) (3 Replies)
Discussion started by: zackz
3 Replies

6. Programming

multithreading on OSX

Hi all, I have a query about multithreading. What I would like to do is, at the start of my main update() function, start a couple of threads in parallel, once they are all complete carry on with my main update function. void update() { thread1->update(); // fluid solver ... (3 Replies)
Discussion started by: memoid
3 Replies

7. UNIX for Advanced & Expert Users

multithreading in UNIX

Hi, Can you please give me a suitable reference to learn multithreading programming in C in UNIX? Thanks (3 Replies)
Discussion started by: naan
3 Replies

8. Shell Programming and Scripting

Multithreading program

Hi I need to insert 1million records into MySQL database, but it is taking lot of time as there is no bulk insert support. I want to spawn 10 processes which will insert 100k records each parallely. Can somebody help me with a example program to execute this task through shell scripting. (5 Replies)
Discussion started by: sach_roger
5 Replies

9. Programming

Help with multithreading

I take this question of the The Linux Programming Interface: A Linux and Unix System Programming page 652 exercise 30.1 I want someone to explain the under line statement because it sounds complex to me couldn't understand anything 30-1 Modify the program (thread_incr.c) so that each loop in... (3 Replies)
Discussion started by: fwrlfo
3 Replies
PTHREAD_ATTR(3) 					   BSD Library Functions Manual 					   PTHREAD_ATTR(3)

NAME
pthread_attr_getstacksize, pthread_attr_setstacksize -- thread attribute operations SYNOPSIS
#include <pthread.h> int pthread_attr_getstacksize(const pthread_attr_t *restrict attr, size_t *restrict stacksize); int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); DESCRIPTION
Thread attributes are used to specify parameters to pthread_create(). One attribute object can be used in multiple calls to pthread_create(), with or without modifications between calls. The functions pthread_attr_setstacksize() and pthread_attr_getstacksize(), respectively, set and get the size of the stack that is to be cre- ated for the new thread. The stack size attribute is set within the attr argument, which can subsequently be used as an argument to pthread_create(). RETURN VALUES
If successful, these functions return 0. Otherwise, an error number is returned to indicate the error. pthread_attr_getstacksize() returns the stacksize attribute value in stacksize if successful. ERRORS
pthread_attr_getstacksize() will fail if: [EINVAL] Invalid value for attr. pthread_attr_setstacksize() will fail if: [EINVAL] Invalid value for attr. [EINVAL] stacksize is less than PTHREAD_STACK_MIN. [EINVAL] stacksize is not a multiple of the system page size. SEE ALSO
pthread_create(3), pthread_attr_init(3), pthread_attr_setstackaddr(3) STANDARDS
pthread_attr_setstacksize(), pthread_attr_getstacksize() conform to ISO/IEC 9945-1:1996 (``POSIX.1'') BSD
December 31, 2007 BSD
All times are GMT -4. The time now is 05:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy