pthread_create blows up

Applications, development tools, FPGA, C, WEB
Post Reply
jmadsenee
Posts: 47
Joined: Fri Apr 17, 2015 7:38 pm
Location: Richmond, VA, USA

pthread_create blows up

Post by jmadsenee » Thu Dec 10, 2015 11:03 pm

Hi All,

I am trying to create a thread to monitor digital IO in a modified scope app. I pretty much copied the pthread code from the worker.c. In my code I have:

Code: Select all

void *rp_io_worker_thread(void *args);
pthread_t 		*rp_io_thread_handler = NULL;

...

int ext_io_init(void)
{
    int ret_val;
...
    ret_val = pthread_create(rp_io_thread_handler, NULL, rp_io_worker_thread, NULL);
    if(ret_val != 0)
...
}

void *rp_io_worker_thread(void *args)
{
	rp_ioState_t 			state;

	while(1)
	{
	    usleep(10000);

	    pthread_mutex_lock(&rp_io_ctrl_mutex);
	    state = rp_io_state;
	    pthread_mutex_unlock(&rp_io_ctrl_mutex);

	    if (state == RP_IO_QUIT)
	    	break;
	}

	return 0;
}
Seems like it should be pretty simple... But, if I put a breakpoint right after the pthread_create, it never reaches it, so I can't even look for an error code.

Anyone have any thoughts? Please? It would be greatly appreciated!

John

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: pthread_create blows up

Post by Nils Roos » Fri Dec 11, 2015 1:57 am

You don't show it, so the question is: do you allocate memory for the pthread_t ? Because pthread_create assumes that it can write to the pointer it is handed. If it's still NULL - bang, SIGSEV.

jmadsenee
Posts: 47
Joined: Fri Apr 17, 2015 7:38 pm
Location: Richmond, VA, USA

Re: pthread_create blows up

Post by jmadsenee » Fri Dec 11, 2015 3:56 pm

Thanks, Nils! You saved my butt again! :D Dealing with an operating system is SO much more complex than bare metal... I assumed that declaring it -

Code: Select all

pthread_t *rp_io_thread_handler = NULL;
- allocated memory for it. :oops: Then the debugger gave me no hint of what went wrong.

Thanks again!

John

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 84 guests