473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

multi threading in C

Pls. give some sample code for understanding multithreading in C.
Sep 28 '06 #1
4 2433
Banfa
9,065 Expert Mod 8TB
There is no multithreading in C, there may be some provided by your platform though
Sep 28 '06 #2
you can use winAPI to do that if you are writing a simple console application (IE CreateThread())
However, it is not recommended to use API commands directly because they cause instability.
Sep 28 '06 #3
Banfa
9,065 Expert Mod 8TB
However, it is not recommended to use API commands directly because they cause instability.
Where on earth did you hear that and if you don't use them directly how should you use them? Through the bloat code that is the MFC?

I have been successfully using the Windows API directly for 15 years.
Sep 28 '06 #4
I haven't done multithreading in C/C++, but the direct use of WINAPI thread functions in VB or VB.NET create some major instabilites in the program. Like, you cannot call the same function more than once or you'll get an exception. Sometimes the program would just hang executing a threaded function. So you end up using some components to do threading for you. I don't know if it's the same in C/C++.

looking at the API documentation you should be able to execute a thread using this code (C++)
Expand|Select|Wrap|Line Numbers
  1.     HANDLE mHandle;
  2.     DWORD data;
  3.     mHandle = CreateThread( NULL, 0, threaded_func, &data, 0, NULL);
  4.  
  5.         // your threaded function would look something like this
  6.         DWORD WINAPI threaded_func (LPVOID myParam) {
  7.         // do something
  8.         }
  9.  
Note that you'll have to use WinAPI to communicate with the program from the threaded function (instead of cout you'd use WriteConsole() and etc)
Sep 29 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Stuart Norris | last post by:
Dear Group, I am attempting to write a "splash" and "status" Form using a second thread. I wish to use this Form to display status information to the user when I do CPU intensive work in my...
13
by: notregister | last post by:
my program have as many as 8 threads running at a same time. can different threads open a same file at the same time? let say thread1 open a file abc.txt at the same time with thread 2, both doing...
2
by: NiponW | last post by:
Hi, I have SQL SERVER 2000 SP4 Enterprise , Windows 2003 Enterprise on Xeon 4 Processors (now with multi-threading CPU) and I have questions which seem weirds to me (used to have the same...
20
by: dotyet | last post by:
Hi Everyone, It would be a real big help if anyone can shed light on whether DB2 UDB 8.2 on Solaris will make optimum use of a Sun T2000 server. The server has 1 CPU with 8 cores and each core...
0
ammoos
by: ammoos | last post by:
hi friends pls help me.. i got an assignment which i feel very difficult to me.. i dont have more knowledge about multi-threading in .net... the assignment details is below.... pls help me... i...
14
by: Akihiro KAYAMA | last post by:
Hi all. I found cooperative multi-threading(only one thread runs at once, explicit thread switching) is useful for writing some simulators. With it, I'm able to be free from annoying mutual...
5
by: George Maicovschi | last post by:
As multi-threading is not built in PHP I've been using a hack letting the Apache server handle the multi-threading issues, but I'm really curious of other approaches to this issue. If anyone has...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
Sorry this is so long winded, but here goes. Following the model of http://msdn2.microsoft.com/en-us/library/system.runtime.remoting.channels.ipc.ipcchannel.aspx I made a remote object using the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.