Sponsored Content
Top Forums UNIX for Advanced & Expert Users User defined stacks for threads using glibc-2.3.5 Post 302180395 by ramen_noodle on Monday 31st of March 2008 03:43:00 AM
Old 03-31-2008
Not nearly enough information. There are a tremendous number of
gotchas in using pthread_attr_setstack.

See suns docs (not entirely on subject, but generic enough to be helpful) and the man page itself.
Multithreaded Programming Guide


header
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

typedef struct custom_thread {
        int cr_return;
	int thread_stack_size;
	pthread_t tid;
	pthread_attr_t attr;
	void *newstack;
} CTHREAD;


extern CTHREAD *init_custom_thread(int, int (*)(void *));
extern void destroy_custom_thread(CTHREAD *);

library
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>



extern CTHREAD *init_custom_thread(int sz, int (*teststackalloc)(void *arg)) {
CTHREAD *ret;

               if ( (ret = malloc(sizeof(*ret))) == NULL) {return NULL;}
               ret->thread_stack_size = sz;
               if ( (ret->newstack = malloc(sz)) == NULL) {free(ret); return NULL;}
               if (teststackalloc!= NULL)
                    if (teststackalloc(ret->newstack) != 0) {free(ret->newstack); free(ret); return NULL;}
               }
               pthread_attr_init(&ret->attr);
               ret->cr_return = pthread_attr_setstack(&ret->attr,ret->newstack,ret->thread_stack_size);
               return ret;
}

extern void destroy_custom_thread(CTHREAD *arg) {

                                  if (arg->newstack != NULL) {free(arg->newstack); arg->newstack = NULL;}
                                  free(arg);
                                  arg = NULL;
}

test
Code:
#include "custom_stack.h"
#include <limits.h>

void *hello_world(void *arg) {
                             
                  printf("Hello world from thread id %d.\n",pthread_self());
                  pthread_exit(NULL);
}

int main(void) { 
CTHREAD *new_id;

               new_id = init_custom_thread(PTHREAD_STACK_MIN * 2, NULL);
               if (new_id == NULL) {return 1;}
               pthread_create(&new_id->tid,&new_id->attr,hello_world,NULL);
               pthread_join(new_id->tid,NULL);
               destroy_custom_thread(new_id);
               return 0;
}

Hopefully the above will point out any obvious errors you are making.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk user-defined function

HELP!!!! I am in an on-line shell programming class and have a question. Here is the data: Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201 Susan Dalsass:(206) 654-6279:250:60:50 (There are 12 contribuors total) This database contains names, phone... (1 Reply)
Discussion started by: NewbieGirl
1 Replies

2. AIX

User defined signal 1

Hi, I am just running a incremental back-up on one of my server. But these days It abrubtly fails with below error. ========== User defined signal 1 =========== When I rerun the back-up, It completed successfully.Earlier this was not happening. Any Idea, what could be the problem... (0 Replies)
Discussion started by: nitesh_raj
0 Replies

3. UNIX for Dummies Questions & Answers

User defined service

I want to add a new IP service which executes a script on SCO OS5. I have amended /etc/services and added to port number (3333) I have amended /etc/inetd.conf and added a line for this service but I can't get it to execute my own shell script When I telnet to the IP address on port 3333 I... (1 Reply)
Discussion started by: markdrury
1 Replies

4. Shell Programming and Scripting

need help with User Defined Function

Dear Friends, I need a help regarding User defined function in shell script. My problem is as follows: my_func.sh my_funcI(){ grep 'mystring' I.dat } my_funcQ(){ grep 'mystring' Q.dat } myfuncI myfuncQ But As both the function has same function only the... (11 Replies)
Discussion started by: user_prady
11 Replies

5. Linux

User defined stacks for threads using glibc-2.3.5

Hi, I am currently working with threads using linux 2.6.11 and glibc 2.3.5 on x86. When i am trying to create thread with user defined stacks glibc gives segmentation fault. I have written a wrapper to pthread_create () and generated shared object for the same. When i am trying to create any... (0 Replies)
Discussion started by: mysterious
0 Replies

6. Programming

add more user-defined signals

Hi Is there a way to add more user-defined signals? I am currently using SIGUSR1 and SIGUSR2 - but I need another one. How can I do that? Thanks! (9 Replies)
Discussion started by: naamabm
9 Replies

7. Shell Programming and Scripting

User defined functions in awk

Hi; Is der ne to to use user defined functions for the values in awk find $1 -type f -ls | nawk '{{print "|"$3"|"$5"|"$6"|"$8"|"$9"|"$10"|"} for(i=11;i<=NF;i++){printf("%s",$i)}}' In above command i want to append some values returned by user functions on line. thnks; ajay (1 Reply)
Discussion started by: ajaypadvi
1 Replies

8. UNIX for Dummies Questions & Answers

user defined commands

Hi, i would like to create user defined commands. e,g: if an user executes , mkdircd test then a directory called test should be created and it should be cd to test. How i can create the command mkdircd with below action: mkdir $1 && cd $1. Please help me in achieving this (7 Replies)
Discussion started by: pandeesh
7 Replies

9. UNIX and Linux Applications

Install glibc-debug for glibc-2.11.3-17.31.1 on SLES 11

I have to debug a function getopt_long in glibc-2.11.3-17.31.1. For that how can I download and install its corresponding glibc-debug on SLES 11? (8 Replies)
Discussion started by: rupeshkp728
8 Replies
PAPI_remove_event(3)						       PAPI						      PAPI_remove_event(3)

NAME
PAPI_remove_event - removes a hardware event from a PAPI event set. SYNOPSIS
Detailed Description A hardware event can be either a PAPI Preset or a native hardware event code. For a list of PAPI preset events, see PAPI_presets or run the papi_avail utility in the PAPI distribution. PAPI Presets can be passed to PAPI_query_event to see if they exist on the underlying architecture. For a list of native events available on the current platform, run papi_native_avail in the PAPI distribution. @par C Interface: int PAPI_remove_event( int EventSet, int EventCode ); @param[in] EventSet -- an integer handle for a PAPI event set as created by PAPI_create_eventset @param[in] EventCode -- a defined event such as PAPI_TOT_INS or a native event. @retval PAPI_OK Everything worked. @retval PAPI_EINVAL One or more of the arguments is invalid. @retval PAPI_ENOEVST The EventSet specified does not exist. @retval PAPI_EISRUN The EventSet is currently counting events. @retval PAPI_ECNFLCT The underlying counter hardware can not count this event and other events in the EventSet simultaneously. @retval PAPI_ENOEVNT The PAPI preset is not available on the underlying hardware. @par Example: * int EventSet = PAPI_NULL; * int ret; * * // Create an empty EventSet * ret = PAPI_create_eventset(&EventSet); * if (ret != PAPI_OK) handle_error(ret); * * // Add Total Instructions Executed to our EventSet * ret = PAPI_add_event(EventSet, PAPI_TOT_INS); * if (ret != PAPI_OK) handle_error(ret); * * // Start counting * ret = PAPI_start(EventSet); * if (ret != PAPI_OK) handle_error(ret); * * // Stop counting, ignore values * ret = PAPI_stop(EventSet, NULL); * if (ret != PAPI_OK) handle_error(ret); * * // Remove event * ret = PAPI_remove_event(EventSet, PAPI_TOT_INS); * if (ret != PAPI_OK) handle_error(ret); * See Also: PAPI_cleanup_eventset PAPI_destroy_eventset PAPI_event_name_to_code PAPI_presets PAPI_add_event PAPI_add_events Author Generated automatically by Doxygen for PAPI from the source code. Version 5.2.0.0 Tue Jun 17 2014 PAPI_remove_event(3)
All times are GMT -4. The time now is 08:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy