🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #6374

threads memory access

#6374
From: Jonathan Benedicto
Date: Fri, 20 May 2005 20:40
21 lines
1904 bytes
I'm building an app that contains 3 threads. 2 of those threads send 
data to the 3rd one. I don't want to create a new char buffer every 
time I need to send data from one of those threads to the 3rd one, so 
I was wondering if a simple locking mechanism would suffice.

Maybe using a struct { char *Block; int BlockSize; bool Locked; }. The 
1st and 2nd threads allocate their own vector of this struct, and 
resize it to 10, init the variables etc.

Now, when they need a buffer, they just loop through the vector, 
finding one with its Locked == false, and then set the Locked to true, 
fill the char* and int, and then send a pointer to it to the 3rd 
thread. Once the 3rd thread is finished with it, it just sets the 
Locked to false.

Would it cause a problem if the 1st and 3rd, or the 2nd and 3rd, did 
read / write to Locked at the same time ? It does not seem like it, 
but I thought I'd better get a second opinion.

Jonathan
 
Technical Details
Message-ID: <428e4b3f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newshosting.com!nx01.iad01.newshosting.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f662da50ec5f6f69,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jonathan Benedicto" <incorrect@no.server>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: threads memory access
Date: Fri, 20 May 2005 16:40:35 -0400
Lines: 23
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 64.231.16.168
Message-ID: <428e4b3f$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1116621631 64.231.16.168 (20 May 2005 13:40:31 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newshosting.com!nx01.iad01.newshosting.com!diablo.voicenet.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail