Sponsored Content
Top Forums Programming Thread parameter in ANSI C makes a segmentation fault Post 302519975 by sehang on Thursday 5th of May 2011 01:45:50 PM
Old 05-05-2011
Quote:
Originally Posted by Corona688
Try fprintf(stderr, "%p\n", v); to see if the pointer value has become corrupted somehow.

If all you're passing is one integer, why allocate memory at all?

void *value=(void *)42;
int ivalue=(int)(value);

If that's not all you're doing, post a more complete portion of your code so we can see what's actually going on.
Thanks, I will use fprintf to catch the pointer value.

Before I post the problem on the forum, I tried to use
Code:
 void *value=(void *)42;
  int ivalue=(int)(value);

But the problem still happened. At that time, I wrote these codes in another way; it is the reason why I use struct to pass parameters.

I have another idea, is it the problem cause by different compile options?
Code:
 gcc -O3 *.c

Code:
  gcc *.c

However, I have 10-20 source files in the project, it is difficult to put all codes in this forum.

Besides, I used outl(...), iopl(...) to control SPI. Are they also affect this threading?
 

10 More Discussions You Might Find Interesting

1. Programming

Hi! segmentation fault

I have written a program which takes a directory as command line arguments and displays all the dir and files in it. I don't know why I have a problem with the /etc directory.It displays all the directories and files untill it reaches a sub directory called peers which is in /etc/ppp/peers.the... (4 Replies)
Discussion started by: vijlak
4 Replies

2. Programming

segmentation fault

ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do??? thank... (8 Replies)
Discussion started by: rockgal
8 Replies

3. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

4. Programming

segmentation fault

If I do this. Assume struct life { char *nolife; } struct life **life; // malloc initialization & everything if(life->nolife == 0) Would I get error at life->nolife if it is equal to 0. wrong accession? (3 Replies)
Discussion started by: joey
3 Replies

5. Programming

segmentation fault.

This code is causing a segmentation fault and I can't figure out why. I'm new to UNIX and I need to learn how to avoid this segmentation fault thing. Thank you so much. Thanks also for the great answers to my last post.:):b: int main() { mysqlpp::Connection conn(false); if... (3 Replies)
Discussion started by: sepoto
3 Replies

6. Programming

Segmentation fault in C

i have this code int already_there(char *client_names, char *username) { int i; for(i = 0; i<NUM; i++) { printf("HERE\n"); if (strcmp(client_names, username)==0) return(1); } return(0); } and i get a segmentation fault, whats wrong here? (7 Replies)
Discussion started by: omega666
7 Replies

7. UNIX for Advanced & Expert Users

segmentation fault with ps

What does this mean and why is this happening? $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps aux | grep ocular Segmentation fault (core dumped) $ ps Segmentation fault (core dumped) $ pkill okular $ ps... (1 Reply)
Discussion started by: cokedude
1 Replies

8. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

9. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
PTHREAD_ATTR_GET_NP(3)					   BSD Library Functions Manual 				    PTHREAD_ATTR_GET_NP(3)

NAME
pthread_attr_get_np -- get attributes of existent thread LIBRARY
POSIX Threads Library (libpthread, -lpthread) SYNOPSIS
#include <pthread_np.h> int pthread_attr_get_np(pthread_t pid, pthread_attr_t *dst); DESCRIPTION
The pthread_attr_get_np() function is used to get existent thread's attributes. Most fields of pthread_attr_t structure are exact values of attributes provided at thread creation time (as parameter to pthread_create(3) function), except for the stack address. Value returned as dst is supposed to be used in conjunction with pthread_attr_get*() functions to retrieve individual values from pthread_attr_t structure. Parameter dst should point to allocated memory area big enough to fit this structure. It is HIGHLY RECOMMENDED to use pthread_attr_init(3) function to allocate attribute storage. IMPLEMENTATION NOTES
The pthread_attr_get_np() function will always return a pointer to the thread's real stack address, regardless of its value in the original attributes structure. RETURN VALUES
If successful, pthread_attr_get_np() function returns 0. Otherwise, an error number is returned to indicate the error. EXAMPLES
size_t my_thread_stack_size(pthread_t pid) { pthread_attr_t attr; size_t size; pthread_attr_init(&attr); pthread_attr_get_np(pid, &attr); pthread_attr_getstacksize(&attr, &size); pthread_attr_destroy(&attr); return(size); } ERRORS
The pthread_attr_get_np() function will fail if: [EINVAL] Invalid value for one of given parameters. [ESRC] No thread could be found corresponding to that specified by the given thread ID. SEE ALSO
pthread_attr_destroy(3), pthread_attr_getdetachstate(3), pthread_attr_getinheritsched(3), pthread_attr_getschedparam(3), pthread_attr_getschedpolicy(3), pthread_attr_getscope(3), pthread_attr_getstack(3), pthread_attr_getstackaddr(3), pthread_attr_getstacksize(3), pthread_attr_init(3) AUTHORS
The pthread_attr_get_np() function and this manual page were written by Alexey Zelkin <phantom@FreeBSD.org>. BSD
January 31, 2003 BSD
All times are GMT -4. The time now is 05:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy