The prototype for pthread_create function is like this:-
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
Last edited by Scott; 11-15-2010 at 02:58 AM..
Reason: Code tags
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)
Hi.
I use C++ and I wishes to create a thread with the pthread_create function, my question is, how can I do this if I wish that the function will be a member of the class ??
I know from windows programming that I can declare a static function like this
static unsigned int __stdcall... (7 Replies)
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)
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 MOJAVE
pthread_attr_getguardsize
PTHREAD_ATTR(3) BSD Library Functions Manual PTHREAD_ATTR(3)NAME
pthread_attr_init, pthread_attr_destroy, pthread_attr_setstack, pthread_attr_getstack, pthread_attr_setguardsize, pthread_attr_getguardsize
-- thread attribute operations
SYNOPSIS
#include <pthread.h>
int
pthread_attr_init(pthread_attr_t *attr);
int
pthread_attr_destroy(pthread_attr_t *attr);
int
pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
int
pthread_attr_getstack(const pthread_attr_t * restrict attr, void ** restrict stackaddr, size_t * restrict stacksize);
int
pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
int
pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize);
int
pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
int
pthread_attr_getguardsize(const pthread_attr_t *attr, size_t *guardsize);
int
pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
int
pthread_attr_getstackaddr(const pthread_attr_t *attr, void **stackaddr);
int
pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
int
pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
int
pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
int
pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
int
pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
int
pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param);
int
pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
int
pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy);
int
pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
int
pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
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 pthread_attr_init() function initializes attr with all the default thread attributes.
The pthread_attr_destroy() function destroys attr.
The pthread_attr_set*() functions set the attribute that corresponds to each function name.
The pthread_attr_get*() functions copy the value of the attribute that corresponds to each function name to the location pointed to by the
second function parameter.
RETURN VALUES
If successful, these functions return 0. Otherwise, an error number is returned to indicate the error.
ERRORS
The pthread_attr_init() function will fail if:
[ENOMEM] Out of memory.
The pthread_attr_destroy() function will fail if:
[EINVAL] Invalid value for attr.
SEE ALSO pthread_attr_affinity_np(3), pthread_attr_get_np(3), pthread_create(3)STANDARDS
pthread_attr_init(), pthread_attr_destroy(), pthread_attr_setstacksize(), pthread_attr_getstacksize(), pthread_attr_setstackaddr(),
pthread_attr_getstackaddr(), pthread_attr_setdetachstate(), and pthread_attr_getdetachstate() functions conform to ISO/IEC 9945-1:1996
(``POSIX.1'')
The pthread_attr_setinheritsched(), pthread_attr_getinheritsched(), pthread_attr_setschedparam(), pthread_attr_getschedparam(),
pthread_attr_setschedpolicy(), pthread_attr_getschedpolicy(), pthread_attr_setscope(), and pthread_attr_getscope() functions conform to
Version 2 of the Single UNIX Specification (``SUSv2'')
BSD January 8, 2010 BSD