Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


Closed Thread
  Search this Thread
Old 11-19-2015, 11:59 PM   #1
LQ Newbie
Registered: Nov 2015
Posts: 3

Rep: Reputation: Disabled
Multithreaded program for UART communication


I am new comer to linux programing.I need to run a multithreaded application which will read and write data to 7 UART ports.
for each UART port there will be 2 deidcated threads (i.e. read and write threads).I have a c++ code which creates thread to read and write data to any particualr UART port.But i want to run all the 7 ports parallel.Plese help me to know how i need to modify the below code so that it can create 7 write and read threads for 7 UART ports and could simultaneoulsy read/write from/to all the ports.
Thank u so much in advance.

void *Uartsend(void * threadParameter);
void *Uartread(void * threadParameter);

int m_fd = -1;
struct termios m_tio;
int trun = 1;
int rrun = 1;
pthread_t p_Uartsend, p_Uartread;

int main(int argc, char *argv[])
int i, ret;
pthread_t p_Uartsend, p_Uartread;
void *thread_res;

//set baud rate,data bits.stop bit,parity nd flow control
setup serial port();

strncpy(port.uart_dev_name, argv[1], MAX_UART_NAME_LEN);

//Open the serial port
m_fd = SerialPort_Init(port, &m_tio);

// create write thread
ret = pthread_create(&p_Uartsend, NULL, Uartsend, NULL);
if (ret < 0)

// create read thread
ret = pthread_create(&p_Uartread, NULL, Uartread, NULL);
if (ret < 0)

ret = pthread_join(p_Uartsend, &thread_res);
ret = pthread_join(p_Uartread, &thread_res);
printf("\nExiting Test\n");
return 0;


void *Uartsend(void * threadParameter)
double speed;
double time;
int strLen = sizeof(test_str);
int writtenBytes = 0;
writtenBytes = Serial_WriteData(m_fd, test_str, strLen);

} while(1); // Run just once

return 0;
Old 11-20-2015, 09:49 AM   #2
Registered: Jun 2000
Distribution: Debian, Red Hat, Slackware, Fedora, Ubuntu
Posts: 13,020

Rep: Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749Reputation: 3749
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Multithreaded program for UART ruc Linux - Newbie 5 12-01-2015 07:46 AM
communication between SOC and MCU over serial UART girmaji Linux - Hardware 1 12-17-2013 06:09 PM
[SOLVED] multithreaded program,pthread ankit,garg Programming 6 01-19-2012 05:27 AM
Problem with a MultiThreaded program in C++? jeremy28 Programming 3 10-23-2010 08:05 PM
Multithreaded Program Ashok_mittal Linux - Newbie 2 01-04-2008 12:56 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:46 AM.

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