X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:from:content-type:subject:date:to :mime-version; q=dns; s=default; b=JuKX/yrLgnj4Xg4y/t1wqly+wK3Dq OD6N4l2F3KTiYTc1TACHoXDGfKj2M79zaaPriSSkhQsRMxNhvTI7AA5uNFuPX59v zC6iVbXc/FZcPKu2Vhh27jueKz3oUdLw0HRMKDZsLpGv4uPXAUDXm4OA82yYQ3Z7 u5QmHQljeHLMnA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:from:content-type:subject:date:to :mime-version; s=default; bh=5vmAAqHn6qU2rr8fky4UyS/KteI=; b=DVj 5w0f5R0vptso5MqGa/zImVMr+MIaqf06AqioBtGSsO5QxUcAxqX7tfnximEvph1G RiJMctjezrDGH9m5mWUozw4fy1ySBnGxiwh0dcux5CE06JEKnbWt7vYfOM0ewAIr 0xS7QvqBcxKmynpQqlU6595hPp30uK9ZI+Dz3xso= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: blu0-omc1-s3.blu0.hotmail.com X-TMN: [vsBvQn3RRRieL0+pMredY1gVy8+gI3Wo] Message-ID: From: Mihail Stefanov Content-Type: multipart/mixed; boundary="Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34" Subject: After call to SwitchToFiber, malloc hangs Date: Fri, 3 Jan 2014 12:59:53 +0200 To: cygwin AT cygwin DOT com MIME-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="us-ascii" Hi, I have problem with malloc hanging when I SwitchToFiber. I have current env= ironment: =20 CYGWIN_NT-6.1 win7-dev 1.7.27(0.271/5/3) 2013-12-09 11:54 x86_64 Cygwin (Wi= ndows 7, x64) I am trying to use Windows Fibers API in cygwin environment. All is working= fine, till the moment I call SwitchToFiber and then malloc. The processor = CPU usage goes to 50% and after some time to 100%. In most cases this a res= ult of memory corruption. In case I do not call malloc, all is working fin= e. Is this something to do with the stack? I made small test project attached to the email. --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34 Content-Disposition: attachment; filename="fiber.c" Content-Type: application/octet-stream; name="fiber.c" Content-Transfer-Encoding: quoted-printable #include =0D=0A= #include "fiber.h"=0D=0A= =0D=0A= #define STACK_SIZE (1024*1024)=0D=0A= =0D=0A= void=0D=0A= init_fiber(fiber_t *fiber)=0D=0A= {=0D=0A= =0D=0A= assert(fiber);=0D=0A= =0D=0A= DWORD ret =3D 0;=0D=0A= void *p_fiber =3D 0;=0D=0A= =0D=0A= p_fiber =3D GetCurrentFiber();=0D=0A= if (p_fiber !=3D NULL && p_fiber !=3D (void*)0x1E00) {=0D=0A= fiber->f_pointer =3D p_fiber;=0D=0A= fiber->init =3D 1;=0D=0A= return;=0D=0A= }=0D=0A= =0D=0A= p_fiber =3D ConvertThreadToFiber(NULL);=0D=0A= if(p_fiber) {=0D=0A= fiber->f_pointer =3D p_fiber;=0D=0A= fiber->init =3D 1;=0D=0A= } else {=0D=0A= ret =3D GetLastError();=0D=0A= }=0D=0A= }=0D=0A= =0D=0A= =0D=0A= void=0D=0A= prepare_fiber(size_t stack_size, fiber_t *fiber, void *code, void* arg)=0D= =0A= {=0D=0A= assert(fiber);=0D=0A= assert(code);=0D=0A= fiber->f_pointer =3D CreateFiber(stack_size, (LPFIBER_START_ROUTINE)cod= e, (LPVOID)arg);=0D=0A= assert(fiber->f_pointer);=0D=0A= }=0D=0A= =0D=0A= void=0D=0A= release_fiber(fiber_t *fiber)=0D=0A= {=0D=0A= if (fiber->f_pointer) {=0D=0A= DeleteFiber(fiber->f_pointer);=0D=0A= }=0D=0A= fiber->f_pointer =3D NULL;=0D=0A= }=0D=0A= =0D=0A= void=0D=0A= switch_fiber(fiber_t *to, fiber_t *from)=0D=0A= {=0D=0A= assert(from->f_pointer);=0D=0A= BOOL isFiber =3D IsThreadAFiber();=0D=0A= if (!isFiber)=0D=0A= ConvertThreadToFiber(0);=0D=0A= =0D=0A= to->f_pointer =3D GetCurrentFiber();=0D=0A= SwitchToFiber(from->f_pointer);=0D=0A= =0D=0A= if(!isFiber)=0D=0A= ConvertFiberToThread();=0D=0A= }=0D=0A= =0D=0A= void fiber_code(void* arg)=0D=0A= {=0D=0A= void *p =3D malloc(1);=0D=0A= }=0D=0A= =0D=0A= int main(void)=0D=0A= {=0D=0A= fiber_t from;=0D=0A= fiber_t to;=0D=0A= init_fiber(&from);=0D=0A= prepare_fiber(0, &from, fiber_code, 0);=0D=0A= switch_fiber(&to, &from);=0D=0A= =0D=0A= }=0D=0A= --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34 Content-Disposition: attachment; filename="fiber.h" Content-Type: application/octet-stream; name="fiber.h" Content-Transfer-Encoding: quoted-printable #ifndef __FIBER_H__=0D=0A= #define __FIBER_H__=0D=0A= =0D=0A= #include =0D=0A= =0D=0A= typedef struct _fiber=0D=0A= {=0D=0A= void *f_pointer;=0D=0A= int init;=0D=0A= } fiber_t;=0D=0A= =0D=0A= void init_fiber(fiber_t *fiber);=0D=0A= =0D=0A= void switch_fiber(fiber_t *to_fiber, fiber_t *from_fiber);=0D=0A= =0D=0A= void prepare_fiber(size_t stack_size, fiber_t *fiber, void *code, void* arg= );=0D=0A= =0D=0A= void release_fiber(fiber_t *fiber);=0D=0A= =0D=0A= #endif=0D=0A= --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii" Regards Mihail --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --Apple-Mail=_9976AB64-04A9-4800-8A40-CFA0632D3C34--