need help with posix threads


 
Thread Tools Search this Thread
Top Forums Programming need help with posix threads
# 1  
Old 12-23-2009
need help with posix threads

Hi,

I am new to posix threads. The no of threads to be created depends on the runtime. If I get the number of threads,
I need to forward declare

pthread_t mythread[n];

how to do that can I use pointers and use malloc()??

I also have another question. The pthread_join is used to make sure all the threads are completed right?? If I want to spawn new threads and execute threads when a particular set of threads get completed,How to complete it. Is my understanding of pthread_join correct??


function1()
{
for(//some n)
{

pthread_create(..,task1);
pthread_join(...,task1);
}

}

function2()
{

for(//some n)
{

pthread_create(..,task2);
pthread_join(...,task2);
}

}
Does this thing work for the model I ve said??
Thanks & Regards,
brett.

Last edited by brett01; 12-23-2009 at 04:52 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Change value for POSIX

Hi, I have a VM with following configration . 3.10.0-693.1.1.el7.x86_64 #1 SMP Thu Aug 3 08:15:31 EDT 2017 x86_64 x86_64 x86_64 GNU/Linux My current POSIX is :-- Your environment variables take up 2011 bytes POSIX upper limit on argument length (this system): 2093093 POSIX smallest... (15 Replies)
Discussion started by: Abhayman
15 Replies

2. UNIX for Advanced & Expert Users

Linkage of POSIX threads function calls

I wonder if someone knows what is the rationale behind linking function calls of the POSIX threads library at link-time vs. run-time. For example, if I create the following program: #include <pthread.h> void noop() { return; } int main() { pthread_self(); pthread_atfork(noop,... (1 Reply)
Discussion started by: jsimsa
1 Replies

3. UNIX for Advanced & Expert Users

Posix threads

Hi, consider the code below: #include <stdio.h> . . struct myStruct { char *message ; int id; }; . . . void *thread_function( void *ptr ); nt main() { pthread_t thread1, thread2 ,thread3 ; struct myStruct nico1; (2 Replies)
Discussion started by: Behnaz
2 Replies

4. Programming

POSIX threads and data safety

I created multiple POSIX threads (on readhat Linux) in a C program in my app. What I am doing is - I am creating threads equal to the number of CPUs in the system and and equal number of instances of a certain data structure, basically a queue implementation. I am assigning one ID to the thread... (2 Replies)
Discussion started by: radiatejava
2 Replies

5. Programming

Posix

HI, When i am configuring php in SUN Solaris. I am getting the below error. configure: error: Your system seems to lack POSIX threads. Do i need to install POSIX? If so can somebody let me know where can i download POSIX for Solaris 8? Thanks, (2 Replies)
Discussion started by: Krrishv
2 Replies

6. UNIX for Advanced & Expert Users

Threads and Threads Count ?

Hi all, How can I get the list of all Threads and the Total count of threads under a particular process ? Do suggest !! Awaiting for the replies !! Thanks Varun:b: (2 Replies)
Discussion started by: varungupta
2 Replies

7. Programming

POSIX threads

Hello ! Let's supose I have a main function in C , and two POSIX threads. I give you an example down : int main() { int something; char else; void *FirstThread(); void *SecondThread(); .. <start those two pthreads ..> return 0;} void *FirstThread() { ... } void *SecondThread()... (2 Replies)
Discussion started by: !_30
2 Replies

8. UNIX for Dummies Questions & Answers

how to read POSIX?

how to read POSIX? poe six or not? (3 Replies)
Discussion started by: robin.zhu
3 Replies

9. BSD

Posix queues

Hi! Everybody%) I got a question like this: Does my FreeBSD5.1 support Posix queues. Thanks! (7 Replies)
Discussion started by: kamazi
7 Replies
Login or Register to Ask a Question
XInitThreads(3) 						  XLIB FUNCTIONS						   XInitThreads(3)

NAME
XInitThreads, XLockDisplay, XUnlockDisplay - multi-threading support SYNTAX
Status XInitThreads(void); void XLockDisplay(Display *display); void XUnlockDisplay(Display *display); ARGUMENTS
display Specifies the connection to the X server. DESCRIPTION
The XInitThreads function initializes Xlib support for concurrent threads. This function must be the first Xlib function a multi-threaded program calls, and it must complete before any other Xlib call is made. This function returns a nonzero status if initialization was suc- cessful; otherwise, it returns zero. On systems that do not support threads, this function always returns zero. It is only necessary to call this function if multiple threads might use Xlib concurrently. If all calls to Xlib functions are protected by some other access mechanism (for example, a mutual exclusion lock in a toolkit or through explicit client programming), Xlib thread ini- tialization is not required. It is recommended that single-threaded programs not call this function. The XLockDisplay function locks out all other threads from using the specified display. Other threads attempting to use the display will block until the display is unlocked by this thread. Nested calls to XLockDisplay work correctly; the display will not actually be unlocked until XUnlockDisplay has been called the same number of times as XLockDisplay. This function has no effect unless Xlib was successfully initialized for threads using XInitThreads. The XUnlockDisplay function allows other threads to use the specified display again. Any threads that have blocked on the display are allowed to continue. Nested locking works correctly; if XLockDisplay has been called multiple times by a thread, then XUnlockDisplay must be called an equal number of times before the display is actually unlocked. This function has no effect unless Xlib was successfully ini- tialized for threads using XInitThreads. SEE ALSO
Xlib - C Language X Interface X Version 11 libX11 1.6.0 XInitThreads(3)