Here is simple code for multithreading in POSIX:
void* simplethread(void* arg)
{
printf("Hello World\n");
}
int main(void)
{
pthread_t id;
pthread_create(&id, NULL, simplethread, NULL);
return 0;
}
Whether the new thread will run or not depends on the OS. Tricky ... (5 Replies)
Hello
My problem goes like this:
I have used Pthread_create, and I have tryed to create 2 proccess but nothing happens! It does not even matter what the function im trying to create do. It is if im trying to activate an empty function. This is my code.
Any help will be highly appreciated.... (1 Reply)
Im trying to run an application i compiled (iperf) and i get an error telling me that it cant create the pthread. when i ran the ./configuration one of the things it checked was for pthreads which came back ok.
Im not really sure where to even start to resolve this. i have been unable to find... (5 Replies)
I try to compile a sample c code in fedora eclipse 3.2 as managed makefile using pthread library,it shows some error on pthread functions.Error is of undefined reference to pthread.Anybody guide me to solve this problem.
Thanking you (1 Reply)
Hi guys.
H was learning posix threads in C with anjuta IDE. it gives me
undefined reference to `pthread_create'
I know i should compile it like:
gcc -lpthread main.c
how should i import this configuration in anjuta so i can compile inside it? (2 Replies)
The prototype for pthread_create function is like this:-
int pthread_create(pthread_t *thread,pthread_attr_t *attr,void *(*start routine),void *arg);
Q.1 .Why the return type of the start_routine must be void*??
Q.2. Why should we pass arg by converting into void * only ??
Thank You (3 Replies)
Hi,
I'm trying to do my homework assignment but I am having trouble using the pthread_create fucntion.
Here is my code________________
//Alicia Johnson
//sum_pid program
//creates n number of threads. These threads create a random number
//then adds the number to a global array. Then... (1 Reply)
Suppose I have a simple program main() with a global varibale int x=0.
int x = 0;
main()
{
print("%d\n",x);
}
I want to create two threads/process which must access this variable x in sync.
Which one will be better threads( pthread_create ) or process( fork )?
If I go with fork() then... (1 Reply)
Discussion started by: rupeshkp728
1 Replies
LEARN ABOUT HPUX
pthread_create
pthread_create(3T)pthread_create(3T)NAME
pthread_create() - create a new thread of execution.
SYNOPSIS PARAMETERS
thread Pointer to the location where the created thread's ID is to be returned.
attr Pointer to the thread attributes object describing the characteristics of the created thread. If the value is NULL,
default attributes will be used.
start_routine
Function to be executed by the newly created thread.
arg Parameter to be passed to the created thread's start_routine.
DESCRIPTION
The function is used to create a new independent thread within the calling process. The thread will be created according to the attributes
specified by attr. If attr is NULL, the default attributes will be used. The values of the attributes in attr describe the characteris-
tics of the to-be-created thread in detail. Refer to the function for a list of the default attribute values. A single attributes object
can be used in multiple calls to the function
When a thread is created with an attributes object, the attributes are, in effect, copied into the created thread. Consequently, any
change to the attributes object will not affect any previously created threads. Once all threads needing a specific attributes object have
been created, the attributes object is no longer needed and may be destroyed.
When the new thread is created, it will execute which has only one parameter, arg. If returns, an implicit call to is made. The return
value of is used as the thread's exit status.
The created thread's scheduling policy and priority, contention scope, detach state, stack size, and stack address are initialized accord-
ing to their respective attributes in attr. The thread's signal mask is inherited from the creating thread. The thread's set of pending
signals is cleared.
Refer to pthread_exit(3T), pthread_detach(3T), and pthread_join(3T) for more information on thread termination and synchronizing with ter-
minated threads.
On success, the ID of the created thread is returned in thread. If fails, a thread is not created and the contents of thread are unde-
fined.
Thread IDs are guaranteed to be unique only within a process.
NOTE: If the main thread returns from an implicit call to is made. The return value of is used as the process' exit status. The main
thread can terminate without causing the process to terminate by calling
Notes
It is unspecified whether joinable threads that have exited but haven't been joined count against the limit.
RETURN VALUE
Upon successful completion, returns zero. Otherwise, an error number is returned to indicate the error (the variable is not set).
ERRORS
If any of the following occur, the function returns the corresponding error number:
attr in an invalid thread attributes object.
The value specified by
thread is invalid.
The necessary resources to create another thread are not available,
or the number of threads in the calling process already equals
The scheduling policy or scheduling attributes specified in
attr are invalid.
The caller does not have the appropriate privileges to create a thread with
the scheduling policy and parameters specified in attr.
AUTHOR
was derived from the IEEE POSIX P1003.1c standard.
SEE ALSO pthread_exit(3T), pthread_join(3T), fork(2).
STANDARDS CONFORMANCE
Pthread Library pthread_create(3T)