LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-28-2010, 07:35 AM   #1
wybourn
LQ Newbie
 
Registered: Jul 2010
Posts: 14

Rep: Reputation: 0
Problem with threads


I'm trying to create a separate thread for my program which basically polls using the read command. However this new thread seems to block the main thread, anyone know why this could happen.

In main I call this function

pthread_create(&mainEventThread, NULL, GenericEventThread, NULL);

which calls

/*New threads start function */
void *GenericEventThread()
{
short int i, nError = -1;
int nEventNumber;
unsigned char buffer[16];

memset(buffer, '\0', 16);

while(1){
/*Switches read mode to read events from the interrupt pipe */
ioctl(sd, IOC_INT);

/*Reads event packet from the interrupt pipe */
nError = read(sd, buffer, 16);

if(nError != -1){
/*Acknowledge the event once the event number is decode */
nEventNumber = decodeEvent(buffer);
doInterruptAcknowledge(nEventNumber);
doInterruptComplete((int)nEventNumber);
nError = -1;
memset(buffer, '\0', 16);
}
}

}

I've used pthread_self to check that a new thread is being created, so why is the while loop in one thread blocking the main thread from running, I haven't used the join function anywhere in my code.
 
Old 09-28-2010, 02:06 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The thread shouldn't block the main one. However, the read() call may. Are you sure it doesn't block?
 
1 members found this post helpful.
Old 09-29-2010, 01:04 AM   #3
wybourn
LQ Newbie
 
Registered: Jul 2010
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks for pointing that out, yes the problem was that the read was blocking.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem creating threads in C++ mending73 Linux - Newbie 1 09-30-2009 02:51 AM
some threads are become unnoticed because of large number of continious threads deepak_cucek LQ Suggestions & Feedback 9 08-20-2009 11:21 PM
Threads Problem maritos Programming 1 11-28-2005 11:34 PM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
I have a problem with POSIX Threads. AndreasA Programming 2 08-11-2003 02:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration