LinuxQuestions.org
Help answer threads with 0 replies.
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 05-31-2004, 06:33 AM   #1
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Rep: Reputation: 30
Creating a Multithreaded Application


Hi


Just wanted to know how I can create a multithreaded application in Linux and Windows. If anyone can help me, I'd be really grateful.



Thanks.
 
Old 05-31-2004, 10:55 AM   #2
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Well, it matters what you are doing. If you are doing a game, or other media app, look into SDL, it has nice threading. If you are doing a regualar desktop app however, I think you may have yo use some #ifdefs... google it.
 
Old 06-01-2004, 06:32 PM   #3
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
Thanks for the info The_Nerd.
 
Old 06-03-2004, 08:55 AM   #4
seeLnd
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16

Rep: Reputation: 0
Hi, this is a simple example:
Code:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void * thread_func(void *arg)
{
   for ( ; ; ) {
     fputc ('1', stderr); 
     sleep(1);
   }
   return NULL;
}

int main() 
{
  pthread_t thread_id;

  if(pthread_create (&thread_id, NULL, thread_func, NULL) != 0) { 
     fputs("Error: pthread can't be created\n", stderr);
     exit(1);
  }

  for ( ; ; ) {
     fputc ('0', stderr);
     sleep(1);
  }
  return 0;
}
gcc -o thread -lpthread thread.c

Last edited by seeLnd; 06-03-2004 at 09:04 AM.
 
  


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
Creating my own Application Cursor pihu Linux - General 3 09-02-2005 02:53 AM
Creating a wizard like application Diederick Programming 1 07-07-2005 12:58 AM
Creating a C application to be run on another machine guarriman Linux - General 2 01-20-2005 10:13 AM
Closing Socket in MultiThreaded Application Fails laalitseth Red Hat 0 04-21-2004 12:44 AM
trouble creating a link to an application evilmrhenry Linux - Software 3 02-15-2004 01:19 AM

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

All times are GMT -5. The time now is 02:01 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