LinuxQuestions.org
Visit Jeremy's Blog.
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 02-28-2005, 02:58 PM   #1
kris273
LQ Newbie
 
Registered: Mar 2004
Posts: 19

Rep: Reputation: 0
threads and blocking functions


Well I've come across a problem in my coding, not a huge one, but an annoying one for sure.

Basically I have a multi-threaded server, most of the threads consist of listen threads for the people who've logged in. And another thread that everyones input is put into a queue, and the thread excutes their input.

Now I've come to a problem trying to make a kick function, and barely managed to make a log off function, but its still buggy too.

Each player has a loop where it gets their input, puts it on the queue, and then blocks the loop waiting for more input.

But then the excution queue see's that they are trying to quit, and closes their file descriptors.

How ever at this point the thread devoted to the player who is trying to quit has blocked excution, and waits for one more input... of anything, and THEN they are logged off.

So the question is... is there any way to unblock a lowe level "read(FD,..)" funtion?


about the only thing I can think of is to start messing with the thread_canceling, fucntions...

I'm using c++ ... and really just looking for a way for one thread to unblock a blocking function of another thread, particularly a read file descriptor function....

Kris
 
Old 02-28-2005, 03:04 PM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I suggest using select with a timeout. It would, in a major rewrite, probably eliminate the threads. In a minor rewrite, it would allow a timeout from blocking to permit the quit.
 
Old 02-28-2005, 05:14 PM   #3
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
A unix signal will cause read() to return with EINTR. There are issues surrounding the use of signals with threads though, and I don't remember what they all are so you'd need to figure that out.
 
Old 02-28-2005, 05:16 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
It sounds like the cancellation functions are more what you want though
 
  


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
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 09:11 AM
Java Threads vs Native Threads rjmendez Programming 0 08-16-2004 05:58 AM
Blocking functions use in PHP not working... jon_k Linux - Software 0 08-06-2004 05:37 PM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

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

All times are GMT -5. The time now is 10:33 AM.

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