Sponsored Content
Full Discussion: multithreading on OSX
Top Forums Programming multithreading on OSX Post 302207886 by memoid on Saturday 21st of June 2008 12:04:15 PM
Old 06-21-2008
Hi, thanks for the response.

Quote:
One more question, ( sorry if its silly ) do you check/validate the creation of threads ? Since its running in an infinite loop, conditions might go wrong and outbursting with the maximum number of threads that can be created.
I think something like that was happening when I went down the 'create a new thread every loop' approach, which is why I scrapped that idea and went for the 'infinite loop in the thread, but only run the update function when the variable is set' approach.

I think I've actually identified the problem. I think it was the sleep() function in my thread loop. I understand why I need that if the loop is continuously running and doing heavy stuff, but do I need it in my case?

When I comment out the sleep line (As below), the behaviour looks a lot smoother and correct, maybe because as soon as I set the bHasRunThisFrame flag in the thread instance to false, the update function is called almost immediately (which is what I want), whereas with the sleep() function, maybe there was a delay of upto interval before the update kicked in?.... or something :P Is it bad to not have a sleep function in there?

// run the update function in another thread
Code:
void MSAThread::threadedFunction() {						
	while(isThreadRunning()) {
		if( lock() ){
			if(bAutoLoop || !bHasRunThisFrame) {
				update();
				bHasRunThisFrame = true;
				unlock();
//				ofSleepMillis(interval); 
			} else {
				unlock();
			}
		}
	}
}

 

9 More Discussions You Might Find Interesting

1. Programming

Multithreading in Pro*C

:confused: Hi! I have created a Multhreaded Application in Pro*C (using pthreads) with about 5 Threads running simultaneously. The Application is basically to Update a Centralized Table in Oracle, which updates different rows in the Table (Each Thread updates different rows!). The... (16 Replies)
Discussion started by: shaik786
16 Replies

2. UNIX for Advanced & Expert Users

multithreading in UNIX

Hi, Can you please give me a suitable reference to learn multithreading programming in C in UNIX? Thanks (3 Replies)
Discussion started by: naan
3 Replies

3. Shell Programming and Scripting

Multithreading program

Hi I need to insert 1million records into MySQL database, but it is taking lot of time as there is no bulk insert support. I want to spawn 10 processes which will insert 100k records each parallely. Can somebody help me with a example program to execute this task through shell scripting. (5 Replies)
Discussion started by: sach_roger
5 Replies

4. Programming

MultiThreading using Pthreads

Situation: i have multiple pthread_create calls like this: pthread_create(...., ThreadFunc1,.....); pthread_create(...., ThreadFunc2,.....); . . which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same... (3 Replies)
Discussion started by: Sastra
3 Replies

5. IP Networking

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Discussion started by: moti12
0 Replies

6. Programming

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
Discussion started by: moti12
6 Replies

7. Programming

Multithreading in reading file

Dear all, I am having a huge XML file, as below structure <EMPLOYEE> <RECORD id =aaa> <Salary>99999</Salary> <section>ssss</section> </RECORD> <RECORD id =bbb> <Salary>77777</Salary> <section>ssss</section> </RECORD> </EMPLOYEE> This is a 50 GB file I want to read this file in... (9 Replies)
Discussion started by: arunkumar_mca
9 Replies

8. What is on Your Mind?

Alarm interrupt and multithreading

Hi Friends any know how became a friend in this Android Programming Language (0 Replies)
Discussion started by: ljarun
0 Replies

9. Programming

Help with multithreading

I take this question of the The Linux Programming Interface: A Linux and Unix System Programming page 652 exercise 30.1 I want someone to explain the under line statement because it sounds complex to me couldn't understand anything 30-1 Modify the program (thread_incr.c) so that each loop in... (3 Replies)
Discussion started by: fwrlfo
3 Replies
tt_thread_session_set(library call)									       tt_thread_session_set(library call)

NAME
tt_thread_session_set -- set the default session identifier for the current thread SYNOPSIS
#include <Tt/tt_c.h> Tt_status tt_thread_session_set( const char *sessid); DESCRIPTION
The tt_thread_session_set function sets the default session identifier for the currently active thread. The ToolTalk service uses the ini- tial user session as the default session and supports one session per procid. The application can make this call before it calls tt_open to specify which session it wants to connect to in the active thread. To change to another opened session, the application must use either tt_thread_procid_set or tt_default_procid_set. To join other sessions, the procid must first set the new session as the default session, and then initialize and register with the ToolTalk service. The calls required must be in the following order: tt_thread_session_set or tt_default_session_set and then tt_open. The tt_open call may create another ToolTalk procid, the connection to which is identified by a procid. Only one ToolTalk session per pro- cid is allowed. (However, multiple procids are allowed in a client.) There are no API calls to determine the session to which a procid is connected. If it is important for the application to know the session to which it is connected, it must make the following calls in the indicated order: tt_open and then tt_thread_session. ARGUMENTS
sessid Specifies a pointer to the unique identifier string for the session that is to be the default session for the current thread. RETURN VALUE
Upon successful completion, the tt_thread_session_set function returns the status of the operation as one of the following Tt_status val- ues: TT_OK The operation completed successfully. TT_ERR_NOMP The ttsession process is not running and the ToolTalk service cannot start it. TT_ERR_PROCID The current default process identifier is out of date or invalid. TT_ERR_SESSION The specified ToolTalk session is out of date or invalid. TT_ERR_UNIMP The ToolTalk implementation does not support multithreading. TT_ERR_TOOLATE The multithreading feature has not been enabled. APPLICATION USAGE
Some ToolTalk API calls implicitly depend on the current default session. Setting the default session for the specific thread prevents race conditions caused by other threads changing the global default session. SEE ALSO
Tt/tt_c.h - Tttt_c(5), tt_default_procid(3), tt_default_session(3), tt_feature_required(3), tt_thread_procid(3), tt_thread_session(3) tt_thread_session_set(library call)
All times are GMT -4. The time now is 10:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy